1. Internet url regular expression
Http or Https are required, when a lot of internet users don’t even know this protocol exists, as they think every url begins with www.
Some crazy urls (Visit Scotland I’m looking at you!) can have other characters not supported by this expression in them (i.e , or ;).
So in order to get around these little issues I altered the expression a little (see below).
Ever try to force the “Download File” dialog in a clients’s browser window when you download files that may be supported with a MIME type? Here is an example that works with many versions of IE.
This example illustrates a simple technique to download files of any type from you web application to the client browser. In addition to setting the MIME types, the example shows how to force the Download File dialog that allows the user to either run or save the file, even if the file type would normally display in the browser’s window.
On my personal site (http://www.sharkcode.com ), I allow the user to download my resume in various formats including Microsoft Word, HTML, Rich Text and Plain Text. I found that for most users (with IE) the correct application was automatically used to view the document from within their browser (such as Word types like .doc). In all cases, however, I wanted the file to be saved to the client’s workstation, rather than simply being displayed by the browser. When I hosted my own site, I could do this by setting the HTTP Headers with “content-disposition” to force the Download File dialog. Now, using the .NET Response object, I can set these headers directly.
The basic ingredients of this example are quite simple and can be found in a Microsoft article at (http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;q306654&lex).
The Microsoft article includes the following code snippet:
private void Page_Load(object sender, System.EventArgs e)
//Set the appropriate ContentType.
Response.ContentType = “Application/pdf”;
//Get the physical path to the file.
string FilePath = MapPath(“acrobat.pdf”);
//Write the file directly to the HTTP content output stream.
I used this example to write a simple method that accepts a file name as input and a boolean that will force the File Download dialog which allows the client to either run, or save this file to their local workstation.
private void DownloadFile( string fname, bool forceDownload )
string path = MapPath( fname );
string name = Path.GetFileName( path );
string ext = Path.GetExtension( path );
string type = “”;
// set known types based on file extension
if ( ext != null )
switch( ext.ToLower() )
type = “text/HTML”;
type = “text/plain”;
type = “Application/msword”;
if ( forceDownload )
“attachment; filename=” + name );
if ( type != “” )
Response.ContentType = type;
Response.WriteFile( path );
The first few lines of code simply convert the file name argument into a physical path (on the server) and get the various component parts of the name. I only handle the file extension of known types that I’m currently using, but this could be extended to support additional MIME types (see the Microsoft article).
If the forceDownload boolean is true, I use the Response.AppendHeader method to add the “content-disposition” which forces the File Download (save) dialog.
I didn’t find a lot of online help with the “content-disposition” header. In fact, it may even be on its way out in the future. But this currently works fine with IE 6 (and several prior version of IE upon which I’ve tested).
datatable1.Merge(datatable2) .It returns void
ASP.NET File Upload: Workaround for File Size Too Large
add to web.config tag:
<httpRuntime maxRequestLength=”102400″ executionTimeout=”360″/>