It’s a common scenario: user needs to download a file from the server by clicking link or a button in your ASPX page. The server-side code for this is pretty straightforward and looks something like this:
Sub DownloadFile(ByVal i_sServerPath As String, ByVal i_sDisplayName As String)
Dim oFile As FileInfo = New FileInfo(i_sServerPath)
With Response
.Clear()
.ClearHeaders()
.AddHeader("Content-Length", oFile.Length.ToString())
.ContentType = ReturnContentType(oFile.Extension.ToLower())
.AddHeader("Content-Disposition", "attachment; filename=" & i_sDisplayName)
.TransmitFile(oFile.FullName)
.End()
End With
End Sub
The code accepts 2 parameters: i_sServerPath – full path to the file on the server and i_sDisplayName – file name that will be displayed to the user in the “Save As” dialog. Code also populates response headers based on file information. I use this handy function to populate ContentType based on file extention:
Function ReturnContentType(ByVal i_sfileExtension As String) As String
Select Case i_sfileExtension
Case ".htm", ".html", ".log" : Return "text/HTML"
Case ".txt" : Return "text/plain"
Case ".doc" : Return "application/ms-word"
Case ".tiff", ".tif" : Return "image/tiff"
Case ".asf" : Return "video/x-ms-asf"
Case ".avi" : Return "video/avi"
Case ".zip" : Return "application/zip"
Case ".xls", ".csv" : Return "application/vnd.ms-excel"
Case ".gif" : Return "image/gif"
Case ".jpg", "jpeg" : Return "image/jpeg"
Case ".bmp" : Return "image/bmp"
Case ".wav" : Return "audio/wav"
Case ".mp3" : Return "audio/mpeg3"
Case ".mpg", "mpeg" : Return "video/mpeg"
Case ".rtf" : Return "application/rtf"
Case ".asp" : Return "text/asp"
Case ".pdf" : Return "application/pdf"
Case ".fdf" : Return "application/vnd.fdf"
Case ".ppt" : Return "application/mspowerpoint"
Case ".dwg" : Return "image/vnd.dwg"
Case ".msg" : Return "application/msoutlook"
Case ".xml", ".sdxl" : Return "application/xml"
Case ".xdp" : Return "application/vnd.adobe.xdp+xml"
Case Else : Return "application/octet-stream"
End Select
End Function
It’s all good, but what if you need to delete the file from the server immediately after user downloaded it? Continue reading 'ASP.NET: Delete file from server after TransmitFile command'»
Scenario: You’re trying to run an ASP.NET application when suddenly an error is thrown similar to this:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0016: Could not write to output file ‘c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\……..\………\some_code.dll’ — ‘Access is denied. ‘
You gave that folder all possible permissions imaginable and still the error persist. What the? Continue reading 'Solution for ASP.NET access to temporary folder denied error'»
Ordinary when you create a parent-child relationship between DataTables in a DataSet – there is a requirement that all values of the parent columns need to be unique. If they’re not – you will get an error: “These columns don’t currently have unique values“.
But there’re times when you need to make the relationship work even if those values are not unique. The solution is not to create constrain when creating the relationship. This can be done for example by passing FALSE as value for createConstrains parameter of Dataset.Relations.Add method:
oMyDataSet.Relations.Add("MyRel", _
oMyDataSet.Tables("TheParent").Columns("ParentColumn"), _
dtSet.Tables("TheChild").Columns("ChildColumn"), _
False)
If you’re using Crystal Reports 2008 in your ASP.NET application, and after deploying to a 64bit server getting following error:
An error has occurred while attempting to load the Crystal Reports runtime. Either the Crystal Reports registry key permissions are insufficient, or the Crystal Reports runtime is not installed correctly. Please install the appropriate Crystal Reports redistributable (CRRedist*.msi) containing the correct version of the Crystal Reports runtime (x86, x64, or Itanium) required. Please go to http://www.businessobjects.com/support for more information.
then switch your application to 32bit mode. In case of Windows 2003/IIS6 entire server will have to be switched, in case of Windows 2008/IIS7 a dedicated 32bit application pool can be established for your application.
This is probably a very obscure situation, but it happened to me, it could happen to someone else. Scenario: an ASP.NET page with Infragistics UltraWebGrid inside of a WARP panel. A button outside the WARP serves as a trigger for partial postback. First click on the button causes expected partial postback, but on the second click page does full postback and is screwed after that. The issue happens only in IE6/7, page works correctly in IE8.
Another condition – page contains ASP.NET AJAX ScriptManager control with ServiceReference path pointing to an ASMX WebService.
Turned out the issue was caused by project being left in debug mode (in web.config debug=”true”). Which caused WebService page to be loaded with parameter “jsdebug” in query string. Which apparently IE6 and 7 didn’t like very much. Switching to debug=”false” in web.config solved the problem.
ASP.NET, HTML/CSS, Infragistics, Javascript, Rant
|
browser, bug, dotnet, Error, html, Internet Explorer, Microsoft, solution
If you’re using MS Chart Control for .NET Framework 3.5 SP1 (in .NET Framework 4.0 it comes as a part of a framework), you may experience a strange behavior when chart images aren’t rendered on the page:

If you’re using HTTP Handler to serve chart images (image URL looks something like “…/ChartImg.axd?i=chart_24dae5cb1f024c4a89f4fe492f05cc59_0.png“) missing mapping in IIS configuration could be to blame Continue reading 'ASP.NET Chart Control is not rendering image'»
Often you have to operate with flattened data that in reality contains multiple levels of hierarchy. For example it can come as a result of several SQL JOIN statement and look like this:

In this example data consist of static root column, region, site, type and state. And the data has clearly defined hierarchy (e.g. Region “India” has site “Bangalore”, site “Bangalore” has types “Application” and “Area”, type “Application” has states “N/A” and “Testing”).
To load this data into Infragistics UltraWebTree I put together a small procedure: Continue reading 'Using LINQ to bind flat data to Infragistics UltraWebTree'»
If your ASP.NET application worked fine in your Development environment, but after deploying it to staging or production crashes with error:
Could not load type System.Web.UI.ScriptReferenceBase from System.Web.Extensions
most likely it was compiled against .NET 3.5 SP1 but the target machine has original .NET 3.5 framework without SP1. The solution is download Service Pack 1 and install it on target server. Another possibility – compile the project against original .NET 3.5 framework.