DataView dvSortTotalUpdates = new DataView();
dvSortTotalUpdates = dtAllUpdates.DefaultView;
dvSortTotalUpdates.Sort = "UploadDate";
DataTable dtGetBySize = dtAllUpdates.Clone();
for( int i = 0; i < iNumOfRecords; i++ )
{
dtGetBySize.ImportRow(dvSortTotalUpdates[i].Row);
}
return (dtGetBySize);
This is a very subtle yet annoying bug. And it's hard to find.
Fortunately, I found help on the
BCL Team Blog.
Just in case (I've had posts that I linked to disappear in the past) I'll copy here what they say:
We’ve seen cases where our customers have run into issues when using a MemoryStream with GZip compression. The problem can be frustrating to debug and I thought I’ll blog about it in the hope that others would avoid a similar issue. The code for this looks like this;
Byte[] compressedBuffer;
MemoryStream stream = new MemoryStream();
using (GZipStream zip = new GZipStream(stream, CompressionMode.Compress))
{
//compress data
...
//Dont get the MemoryStream data before the GZipStream is closed since it doesn’t yet contain complete compressed data.
//GZipStream writes additional data including footer information when its been disposed
compressedBuffer = stream.ToArray(); //WRONG
}
// CORRECT CODE: call compressedBuffer = stream.ToArray() here after the GZipStream is disposed
The problem arises because the data in MemoryStream is not complete when ToArray is called before the GZipStream is closed. We will write any remaining compressed data and footer information to GZipStream when its being closed. The data in the MemoryStream is still accessible even after its been closed. Both ToArray and GetBuffer methods will return valid data after the MemoryStream has being disposed. This is not so much an issue when another stream like FileStream is used in compression since there is generally time before decompression when a file is used and its ok for the file to be re-opened when that happens.
An example of how to make an aggregated report, grouping together by values:
select count(*) as total ,
count(case WHEN others = 1 THEN 1 END) as [one url],
count(case WHEN others = 2 THEN 1 END) as [two urls],
count(case WHEN others = 3 THEN 1 END) as [three urls],
count(case WHEN others > 3 THEN 1 END) as [all the rest]
from #temp2
I was looking for the code I once used to put the viewstate tag at the bottom of the form tag, instead of the top. I found some code, used an automated VB-to-C# converter, and the results were not good.
I'm not sure if this is a difference between C# and VB or just a bug posted on Scott's blog, but the insertion place was wrong. So I changed that (removed the -1) and also changed the way he checked if the viewstate object was found, so that if not, we'd still have the original html, before removing the tag.
Edit: I now just saw that someone commented on the -1 issue on that page. Anyway, here's my code:
/// <summary>
/// This method overrides the Render() method for the page and moves the ViewState
/// from its default location at the top of the page to the bottom of the page. This
/// results in better search engine spidering.
/// </summary>
/// <param name="writer"></param>
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
string newHtml = string.Empty;
int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
if ((StartPoint >= 0))
{
// does __VIEWSTATE exist?
int EndPoint = (html.IndexOf("/>", StartPoint) + 2);
string ViewStateInput = html.Substring(StartPoint, (EndPoint - StartPoint));
//I'm using newHtml so that if we cannot find the viewsource's right location, we still have the original html
newHtml = html.Remove(StartPoint, (EndPoint - StartPoint));
int FormEndStart = (newHtml.IndexOf("</form>"));
if ((FormEndStart >= 0))
{
//success - so replace the string, putting the viewstate at the end.
html = newHtml.Insert(FormEndStart, ViewStateInput);
}
}
writer.Write(html);
}
Say you want to combine the data from 3 tables - a1, a2, and a3.
Now, you also want to add a special field, let's say it's the year, and it's 2001 for a1 2002 for a2 etc'
In addition, you want the resluting table to have an identity column. What do you do?
This is a real - life scenario which came up today, and here's the solution:
select IDENTITY(int, 1,1) AS id_num , *
into a
from
(
select 2001 as year ,* from a1
union
select 2002,* from a2
union
select 2003,* from a3
) as t
select * from a
Credits due: look at the second post on http://searchvb.techtarget.com/tip/0,289483,sid8_gci932171,00.html
CREATE FUNCTION dbo.fnSplit(
@sInputList VARCHAR(8000) -- List of delimited items
, @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items
) RETURNS @List TABLE (item VARCHAR(8000))
BEGIN
DECLARE @sItem VARCHAR(8000)
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
BEGIN
SELECT
@sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))
IF LEN(@sItem) > 0
INSERT INTO @List SELECT @sItem
END
IF LEN(@sInputList) > 0
INSERT INTO @List SELECT @sInputList -- Put the last item in
RETURN
END
GO
--Test
select * from fnSplit('1,22,333,444,,5555,666', ',')
select * from fnSplit('1##22#333##444','##') --note second item has embedded #
select * from fnSplit('1 22 333 444 5555 666', ' ')
(taken from http://msdn2.microsoft.com/en-us/library/ms998559.aspx)
Choose the Appropriate XML Class for the Job
To help you choose the appropriate .NET Framework class to process XML, consider the following guidelines:
· Use XmlTextReader to process XML data quickly in a forward, read-only manner without using validation, XPath, and XSLT services.
· Use XmlValidatingReader to process and to validate XML data. Process and validate the XML data in a forward, read-only manner according to an XML schema or a DTD.
· Use XPathNavigator to obtain read-only, random access to XML data and to use XPath queries. To create an XPathNavigator object over an XML document, you must call the XPathDocument.CreateNavigator method.
· Use XmlTextWriter to write XML documents. You cannot use XmlTextWriter to update XML documents.
· Use the XmlTextReader and XmlTextWriter, in combination, for simple transformations rather than resorting to loading an XmlDocument or using XSLT. For example, updating all the price element values in a document can be achieved by reading with the XmlTextReader, updating the value and then writing to the XmlTextWriter, typically by using the WriteNode method.
· Use the XmlDocument class to update existing XML documents, or to perform XPath queries and updates in combination. To use XPath queries on the XmlDocument, use the Select method.
· If possible, use client-side XML processing to improve performance and to reduce bandwidth.
Right there: http://www.aprogrammersjournal.com/article.aspx?id=58
The important part is this:
application level parameters
Application level parameters such as session variables or client side cookies are parameters that are page independent. To cach multiple versions of a page based on application level parameters you can use VarByCustom and the global.asax file.
In my case the problem I was faced with was using Forms.Authentication in combination with output caching. If user A logged into my site I did not want it to "Welcome User A" to User B.
he first thing we will need to do is set the location of the output cache to "client or "server, this ensures that the page will not be cached by a proxy server. To learn more about caching location please visit: This Link
Secondly you will need to set up an override function in your global.asax file
<Script language="VB" runat="server">
Public Overrides Function GetVaryByCustomString( _
ByVal context As System.Web.HttpContext, _
ByVal custom As String) As String
Select custom
Case "username"
Return Context.User.Identity.Name
Case Else
Return MyBase.GetVaryByCustomString(context, custom)
End Select
End Function
</script>
And lastly specify your custom variable:
<%@ OutputCache Duration = "1200" VaryByParam="*" Location="Server" VaryByCustom="username" %>
So now if a user logs in he will receive his own custom cached page, as he browses around the site and hits the same pages, he will receive the pages that were cached for him.
Error code 0x8013134b - unable to attach to process.
The website was configured to use ASP .Net 2.0 instead of 1.something.
check it out
My first post, here's a recommendation:
Go and download the .Net 2.0 version of ELMAH.
Very easy and quick to include in your projects, and very useful!
The GotDotNet project for ELMAH is here
Oh, yeah, ELMAH stands for “Error Logging Modules and Handlers”
Update: since GotDotNet was phased out, the project moved to http://www.elmah.org/
I started looking at the .Net Framework 3.0 and I know I would like MS to come with how-to videos for it, like they did for ASP .Net 2.0
also, I'm wondering about the changes it brings for the use of Microsoft Atlas (annoyingly changed to Microsoft Ajax extensions) and the Friendly CSS providers.
VS doesn't tell you what the newer construct is, which is annoying. But here's a useful post to the asp.net forum.
If you have the property OnFinishButtonClick in your wizard, something like this:
OnFinishButtonClick=”Wizard1_FinishButtonClick”
and the sub FinishButtonClick is set to:
Handles Wizard1.FinishButtonClick
Then the sub will be called twice!
This is something I have to google everytime, so it's about time to have a link for it:
ASP .NET videos
Hope the link doesn't change. If it does though, this one might work.
This post is for someone who's like me, i.e., has never used Sebversion before, and the documentation, although there's certainly plenty of it, doesn't really follow the KISS principle.
Software
* Subversion - the version control software.
* TortoiseSVN - GUI for Windows Explorer (not IE)
* AnkhSVN - Add-in that enables the use of Subversion directly from Visual Studio
* SVNService - Runs the Subversion "daemon" as a Service in Windows, on the Server side.
Branches, Tags and Trunk:
* Tagging: You might tag your project when you reach Version 1.0. Then you can go on making changes to your project, but if you need to get back to Version 1.0, you can always use the tagged version of your project to retrieve all the source files exactly as they looked when your reached Version 1.0.
* Branching: If you are working on a project, and want to try some experiments, but you aren't sure you want to keep them, then you can branch the project. After branching, you will have two copies of your project: the main trunk, and the branched version. Work can then continue on both the main trunk, and the branch. Changes to the branch will not be seen in the main trunk, and changes to the trunk will not appear in the branch. Both branches of the code will have acecss to any changes that occurred before the project was branched. As I will explain below, branching is handled in a way to insure that only a minimum amount of server side disk space will be used.
Edit:
I found a very usefull article here
Anybody knows what this means?
It comes from ankhSVN, shows up in the output window, when loading the Visual Studio .Net solution:
Cannot find automation object for project EwdWeb_deploy.
Some manual refresh of project might be necessary.
That "EwdWeb_deploy" project is the web deployment project (explanation here)
I was looking for a way to improve the search box I had on my website.
Then I found Steve C. Orr's article about it, and “saw it was good“.
But, after implementing that in my website, I immidietly saw that somethings, MSN didn't find on my website. Sure, I need to think about SEO and such, but what do you do until everything is fixed?
I took the results from the MSN search API and combined them with the search I already had. I don't want to temper with the results, in case that violates the user agreement, so I was careful only to add resuts, and keep the MSN results in the same order in which they come from MSN.
Protected Sub SearchBox1_SearchResultsReady(ByVal SearchResults As System.Data.DataTable) Handles SearchBox1.SearchResultsReady
'get product search results
Dim ds As DataSet = NewEwdCommon.oProductData.SearchProducts(Request.Params("for"))
Dim dt As New DataTable
dt.Columns.Add(
"Title")
dt.Columns.Add(
"Url")
If ds.Tables(0).Rows.Count > 0 Then
Dim row As DataRow
Dim ProductPageUrlFormat As String = _
Request.ServerVariables(
"SERVER_NAME") & Request.ApplicationPath & _
"/" & Master.VehicleChooser.VehicleArgumentsDirectoryString & _
NewEwdCommon.MyUrl.ProductDetails.Start &
"{0}" & NewEwdCommon.MyUrl.ProductDetails.Finish
ProductPageUrlFormat = ProductPageUrlFormat.Replace(
"//", "/")
ProductPageUrlFormat =
"http://" & ProductPageUrlFormat
For Each row In ds.Tables(0).Rows
Dim sTitle As String = String.Format("{0}, Product {1}, SKU {2} - sale price is {3}", _
row(ProductDB.FieldNames.ProductName), _
row(ProductDB.FieldNames.ProductID), _
row(ProductDB.FieldNames.SKU), _
row(ProductDB.FieldNames.PriceCustomer))
Dim sUrl As String = String.Format(ProductPageUrlFormat, row(ProductDB.FieldNames.ProductID))
dt.Rows.Add(sTitle, sUrl)
Next
'finished, now merge the two data tables:
dt.Merge(SearchResults)
End If
DataList1.DataSource = dt
DataList1.DataBind()
End Sub