.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Downloading file not working with URL Rewritting

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I have implemented URL rewritting in my application. I did it in Application_BeginRequest located in Global.asax. My url rewritting in working fine. Now in order to maintain rewritting during post back.

I have added code line this.Form.Action = Request.RawUrl; in page load event in order to maintain rewritten URL during post back. When I am adding below code on image button click to download file it doesn't work. It says "Internet explorer cannot display webpage". When I am removing line this.Form.Action = Request.RawUrl; from page load then downloading file will start working but URL rewritting will not work on postback. Please let me know work around to handle such condition.

FileInfo objFi = new FileInfo(Server.MapPath(filepath));
this.Form.Action = Request.RawUrl;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + objFi.Name);
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.AddHeader("Content-Length", objFi.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";


View Complete Post

More Related Resource Links

upload file not working



iam using masterpage and ajax update panel, i have child page called  fileupload.aspx,i try to upload the file

but its not working , can i use updatepanel in child page , pls very urgent

looking forward for answer.

New off line application working with sdf file. Need advice


Hey Folks

I am working on a project currently where I need to get data out of a 3rd party vendor's software that uses a .sdf file I looked this up and its a SQL CE file. I was hoping to just link to with with access but thats apparently not going to happen. I need to link to the database extract data from it to a csv file for later use. I also and most important I need to get the data from it and create a report that can be printed while on a customers site that my or may not have web access so I need for this program to be on and off line. I had my webapplication that I have been working on open and was able to bring up the sdf file under the server exploere however I can't seem to get anything out of it when I try to do grid views or detail views errors out.

Can I use one of Visual Studio projects to create this sort of applicaiton if so what would be the best approach. I would love to get an access odbc driver since office is allready installed on the employee's laptop's



Code write file asp.net 2.0 is working in firefox but IE not working.

If Not IsDBNull(ext) Then                                        ext = LCase(ext)                                    End If                                    Select Case ext                                        'Case ".htm", ".html"                                        '    type = "text/HTML"                   

Drag drop functinality not working on Explore View control for file containing special characters in

We have created a control which uses explorer view control for file drag and drop. This functinality works fine for a file having filename without special characters but it gives an error if we drag and drop a file having special characters in the file name. The reason for this is Sharepoint uses WebDAV protocol for file transfer to the Sharepoint document library and WebDAV protocol has limitation that it does'nt accept file with special characters. Please let me know the way how I can accomplish drag and drop of file with special characters in file name, onto Explorer View control with WebDAV.

Drag drop functinality not working on Explore View control for file containing special characters in

We have created a control which uses explorer view control for file drag and drop. This functinality works fine for a file having filename without special characters but it gives an error if we drag and drop a file having special characters in the file name. The reason for this is Sharepoint uses WebDAV protocol for file transfer to the Sharepoint document library and WebDAV protocol has limitation that it does'nt accept file with special characters. Please let me know the way how I can accomplish drag and drop of file with special characters in file name, onto Explorer View control with WebDAV.

Problem in downloading a file code.

hey dere, here is my code.....   void transfer() { string filePath = Server.MapPath("~/download"); string _DownloadableProductFileName = "mob.txt"; System.IO.FileInfo FileName = new System.IO.FileInfo(filePath + "\\" + _DownloadableProductFileName); FileStream myFile = new FileStream(filePath + "\\" + _DownloadableProductFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(filePath).ToString("r"); string _EncodedData = HttpUtility.UrlEncode(_DownloadableProductFileName, Encoding.UTF8) + lastUpdateTiemStamp; Response.Clear(); Response.Buffer = false; Response.AddHeader("Accept-Ranges", "bytes"); Response.AppendHeader("ETag", "\"" + _EncodedData + "\""); Response.AppendHeader("Last-Modified", lastUpdateTiemStamp); Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name); Response.End(); Label1.Text = "hel"; } i have two problems in this code.First while running this code i dont get the file damaged or corrupt. Second problem is dat the code exits at Response.End() and doesnt execute d last line... 

Downloading a .pdf file

Hi. I have a link button which the user clicks on it and will download a .PDF file into their PC.It is  just a file for them to download.Currently, I have the following code.Response.Clear()                Response.Buffer = True                Response.AddHeader("content-disposition", "attachment;filename=Savings Account eStatement.pdf")                Response.Charset = ""                Response.ContentType = "application/vnd.pdf"                Dim objSw As New StreamWriter("Savings Account eStatement.pdf")                objSw.Close()                lblMsg.Text = "Your file created successfully"                lblMsg.ForeColor = Color.Green              

Task scheduler and System.IO.File.WriteAllText() not working properly

I have a simple console application that has this in mainline:  Console.WriteLine(System.String.Format("the current directory is: {0}", System.IO.Directory.GetCurrentDirectory())); System.IO. File.WriteAllText(@"test.txt", "new contents");   Console.ReadLine(); I compile this in VS 2010 and copy the EXE to a directory named "c:\test".  When I run this code in two different OS's via "Task Scheduler" and "Scheduled Task" I get different results.   In Windows Server 2003 R2 "Scheduled Task" this code will create a file as I would expect, c:\test\test.txt with the proper contents written to it.  When I run this same code on Windows 2008 R2 (64 bit version) "Task Scheduler" it writes the expected contents to an unexpected location, c:\C:\Windows\SysWOW64\test.txt. In both environments if I run the exe's from a command line, it writes to c:\test\test.txt as I would expect. As I understand it, if you don't fully qualify the file name in the first parameter of the WriteAllText method it will write the contents to the file in the directory of the executable however this seems to break down when running in the Windows 2008 Task Scheduler.  I know I can fully qualify the file name or put the expected path in a

<%=%> doesnt working if script is in seperate js file.

var a =document.getElementById("<%= TextBoxId1.ClientID %>")this code soesnt working on a seperate javascript file (ofsure linked to aspx file)but works if javascript embedded in aspxwhat if my javascript code is not in aspx ?how can I access autonamed IDs like this ? any idea ?(thank you before any anwer).

.js file not working

I have page calling javascript. <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Java Script Test</title> <script language="javaScript" type="text/javascript" src="javaScript/TestScript.js"></script> </head> <body> <form id="form1" runat="server"> <div align="center"> <p><asp:Label ID="Label1" runat="server" Text="PayBand"></asp:Label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="txtpb" runat="server" onkeyup="insideJS('txtpb','txtGP','txtgross');"></asp:TextBox></p> <p><asp:Label ID="Label3" runat="server" Text="Grade Pay"></asp:Label> &nbsp;&nbsp;&nbsp; <asp:TextBox ID="txtGP" runat="server" onkeyup="insideJS('txtpb','txtGP','txtgross');"></asp:TextBox></p> <p><asp:Label ID="Label2" runat="server" Text="gross"></asp:Label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="txtgross" runat="serv

File Upload Control is not working in Update Panel

hi friend... i am using update panel... in one of my aspx page (ASP.NET 2.0)there is a file upload control in update panel which is used to upload company logo on server..when i remove the update panel.. than file upload is working properly..but when i again place an update panel then file upload control is not working and its giving me error.. in likeIf String.IsNullOrEmpty(fldLogo.PostedFile.FileName.ToString) Then                 as object reference not set to an instance of an object... can any body help me ?any idea ??  

File download from 3 servers not working.


Hi guys,

We have a problem where in the user can download files from an email. A link that will redirect to a page where the code to download the file resides. Before the download the user needs to be logged in to the system for security. The problem is that sometimes for whatever reason when the user clicks the link the download dialog box does not appear and just a blank white page. It happens only on our staging environment where we have 3 servers.. We can't reproduce this in our dev and test env. where we only have one server.

We need help.. thanks.

Below is the actual code.

  Private Sub DownloadFile()
        Dim path As String = ConfigurationManager.AppSettings("JobApplicationDocuments")
        path &= applicationClientId & "\" & jobId & "\" & jobApplicationId & "\" & fileName

        If (System.IO.File.Exists(path)) Then
            Dim fs As System.IO.FileStream = System.IO.File.OpenRead(path)
            Dim file As System.IO.FileInfo = New System.IO.FileInfo(path)
            If file.Exists Then
                Response.AddHeader("Content-Disposition", "attachment; filename=" & orginalFileName.Replace(" ", "_"))

Downloading a document from a sharepoint site to local file system, copy web service returns null

Hi Guys,
               I am trying to get this done for the last 2 days and I am still banging my head to the wall.
All I need to do is to download files from my sharepoint site library that uses integrated windows authentication. I was using copy webservice : getItem method to accomplish this.

CopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

Problem : myByteArray is always returned as NULL

Note: I have tried the same with another site that uses forms authentication but the result was the same (NULL !!)

This is my code:


Copy copy = new CopyService.Copy();


Im downloading a file and checking internet connection im trying to use event to check when the file


I used breakpoint on the event but its never get there.

This is the code of the connection testing of the internet while downloading the file in the contrustor:

if (fdt.http_test()== true)
                    Client.DownloadFile(remote_image_on_server, temp_dir + temp_file);
                    label6.Enabled = true;
                    label6.Visible = true;
                    label6.Text = "Internet connection active";              

System.IO.File.Exists - Not working

I Hide/Show an image based on the existence or not of that image. If the image exists, then I show the image the report has to show. If the image does not exist, then I show a default image. Think of it as an eCommerce web site which shows a catalogue of products. If we do have a picture for that product, then we show the product's picture. If we do not have a picture for that product, then we show a default images that says image not available.

To achieve this, I tried to use System.IO.File.Exists("image path") in the Hidden property of the image field but it does not work.

I thought it could be the due to the location of the image but I also moved the image to my local machine where I am designing this report and it still fails.

I created a very simple console project just to see if the library works and it does, when I run the code on a console application, it perfectly works, it returns True.

I also modified rssrvpolicy.config changing all PermissionSetName to FullTrust and still nothing.

I will really appreciate any possible solution, links, ideas, comments...

Thanks in advance for your help.

Miguel Gonzalez.

property setting in report server (2008) config file is not working as expected.



I have set the <WorkingSetMinimum> property to 2.4GB in my reportserver 2008 config file.

By defintion, <WorkingSetMinimum> setting means,

  1. Lower limit of service memory consumption; memory will not be released if the consumption is below this amount, though the service will not reserve the designated amount of memory when it starts.
  2. If service uses more than the designated amout of memory, it will release back the memory only till this declared value and not beyond that, which means it should keep 2.4GB as designated.

See this link for definition: http://books.google.com/books?id=mzY_Xo_9J-gC&pg=PA589&lpg=PA589&dq=What+is+%3Cworkingsetminimum%3E+in+report+server+configuration+file&source=bl&ots=r_xhRp8erj&sig=E_o0-Dh2SXOgMNrW3sptt5oZrYI&hl=en&ei=f5mjTNeNM5O8ccmErJMI&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCAQ6AEwAw#

Link to css file is two times in web page, css is not working



When I am building and running a webform, the link to a css file is two times in the head.
And the css is not working, can any one help me please.
The code is:

In the view source of the webpage:

   Home - MKB Databasebeheer
</titel><link href="App_Themes/MKB/MKB.css" rel="stylesheet" type=""text/css" /><link
hred="App_Themes/MKB/MKB.css" type="text/css" rel="stylesheet" /><style type="text">

The code in the master page is:

 <head runat="server">
  <title>Mkb Databasebeheer</title>
  <link href="App_Themes/MKB/Mkb.css" rel="stylesheet" type="text/css" />

The code in web.config is:

<page theme="MKB" masterPageFile="~/MKBDatabasebeheer.master: maintainScrollPositionOnPostBack="true" />

I hope that it is clear to you what I have done, and what I have done wrong?



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend