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

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

Downloading a .pdf file

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
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              

View Complete Post

More Related Resource Links

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 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";              

downloading file from sharpoint 2007 with fba authentications



I have to write a program which will automatically download some files from sharepoint 2007 with FBA.

The most important for me is how to autheticate form c# to sharepoint FBA through http.


Downloading an xml file in Web App is of type .aspx



Ive created a Web App where it is possible to download an xml file from the server to the client. It works just fine except that the Save Dialog recognizes the file being dowloaded as of type .aspx and the name of the file as being the name of the page I'm on. The page is called Download.aspx and it contains a button that when clicked executes the following code:

                //sends the content to the client
                Response.ContentType = "text/xml;charset=utf-8";
                Response.AppendHeader("Content-Disposition", "attachment, filename=questionnaire.xml");

The save dialog appears and says:

Name: Download.aspx

Type: ASP.NET Server Page, 1,16KB


If I download the file and open it it contains the correct Xml file content and nothing else, so it is working correctly. It just annoys me that it appears to the user that he is downloading the aspx site (and it shows up as such in windows explorer as well) rather than the xml file which is the actual content.

Does anyone know how I can get the save dialog to show the name and type of my xml file rather than the web page?

Problem in downloading file in asp.net


i am using asp.net 3.5 with C# and sql server 2005 as database. In my project i have to download some file. I do the code for the same but it not working properly.

My code are as follows..

protected void Button1_Click(object sender, EventArgs e)


      //       Do some query here..

       string filepath = Path.GetFullPath(@"E:\New Folder\" + reader["URESUME"].ToString() + "");
                    FileInfo file = new FileInfo(filepath);
                    if (file.Exists)
                        Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);

InfoPath XML File SharePoint Workflow Edit Task Button, XML file is downloading

I am using the inbuilt Approval Workflow on a InfoPath forms library. Now in the Edit Task Page as well as in the Edit Task Dialog that appears from within Outlook, the InfoPath Form's link is given. But as the form is an .XML file, it just gets opened as a normal XML in the browser or gets downloaded. It should open within the Forms Server URL, where InfoPath form gets rendered in the browser itself. How do I change this? This seems to be a common problem posted by many.

Downloading file not working with URL Rewritting



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";


Send email when downloading a file from a document library


I'm setting up a public facing SharePoint site for my company, a software house (did I show my age by calling it that?). We're wanting to put together a list of of software downloads, each item on the list having configured permissions for different groups (such as Group A can see downloads 1 thru 3, Group B can see items 1- 5, and Group C can see all 10 items)

When a logged in group member downloads the file (Send To > Download a copy) or by clicking the litem name, I want to send that person an email, which will contain setup instructions and unlock passwords, etc.

How can this be done?

I've googled and googled, but not been able to find any clues, which is a little unnerving.

A true software developer is one who, when told to 'Go to Hell', sees the 'go to', rather than the destination, as harmful.

File Splitter in .Net

I love to do utility programs in .Net. And this is one of them. As I was playing with JSplit (a free file splitter program), I wondered if I could do it in .Net. The framework supports file operations like reading files in bytes and creating them. It is indeed easy to do file operations in .Net Basics on File operations

Upload Multiple File using JQuery in asp.net

In this article I have explained how to upload multiple files using file upload control. I have used jQuery plugin for uploading multiple files.

I have also explained how to check for file type, file maximum size limit using jQuery & also using server side validation code.

Creating Excel file from C#

I used below coding for create a excel sheet.I got from on web site.
In below coding there is no problem.Its create the excel file.If i run second time,its ask to overwrite the current excel file.If I said "Yes" then it ok ,but If I select cancel button,its generate the Error message.The exception is

Upload a File to a SharePoint Document Library - Part I

The following helper class demonstrates a few techniques that allow documents to be uploaded to a SharePoint document library programmatically without using the API or a custom web service. You don't need to specify a document library name, and it will create any folders specified in the URL as required. File meta data will be updated if any properties are passed.

SmtpClient and Locked File Attachments

Got a note a couple of days ago from a client using one of my generic routines that wraps SmtpClient. Apparently whenever a file has been attached to a message and emailed with SmtpClient the file remains locked after the message has been sent. Oddly this particular issue hasn't cropped up before for me although these routines are in use in a number of applications I've built.

How to call an .exe file in .net

Sometimes a developer has to call an EXE from another EXE. While calling EXE there can be a requirement to pass parameter.

ClientAccessPolicy file in SharePoint 2010

I am upgrading my Silverlight demo code from the old beta to beta 2 and see that there are a few new considerations for the deployment of ClientAccessPolicy.xml files. In a previous post I demonstrated how to do this for SharePoint 2007. The heartburn that I get with that approach is any site collection owner or designer can drag the file into the site collection and open the site up to unwanted client access issues. In 2010 the virtual path provider no longer serves the files from the root of the site collection

Multi File Upload Using JQuery!

Everyone knows about the file upload in .NET. But the multi file upload is some what difficult in .NET. For that purpose we can have some AJAX or JQuery!. Jquery is the latest advanced version. It will give some animated upload. You can try it for your own!!!!
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