Google Search

Google
 

Tuesday, January 22, 2008

DateTime Formatting in GridView,DetailView,FormView

In Asp.Net 2.0 direct datetime formatting for bound column not possible.

To format column into datatime you have to set HtmlEncode="False" property of BoundField.


The Reason behind for this is bydefault data is Html Encoded that prevents to format date.So, set HtmlEncode to False.

Saturday, January 5, 2008

File Download dialog box

Code to open a "save as.." file download dialog box in asp.net 2.
Here,I create a vb.net function for to open file download dialog box.

Use System.IO class for file system. Function argument accepts a File virtual path not physical path.

This code for only .txt file but you also use this code for more extension file.For that change only ContentType.

.htm,.html => "text/HTML"
.txt => "text/plain"
.doc,.rtf => "Application/msword"
.csv,.xls => "Application/x-msexcel"
.pdf =>"Application/pdf"


Function DisplayDownloadDialog(ByVal PathVirtual As String)

Dim strPhysicalPath As String
Dim objFileInfo As System.IO.FileInfo
Try
strPhysicalPath = Server.MapPath(PathVirtual)
'exit if file does not exist
If Not System.IO.File.Exists(strPhysicalPath) _
Then Exit Function
objFileInfo = New System.IO.FileInfo(strPhysicalPath)

Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
objFileInfo.Name)
Response.AddHeader("Content-Length", objFileInfo.Length.ToString())

Response.ContentType = "Text / plain"

Response.WriteFile(objFileInfo.FullName)


Catch
'on exception take no action
'you can implement differently
Finally

Response.End()

End Try
End Function