Cannot open the file .pdf when downLoad from server

 hi all

The segment code below is used to download file from Server to client

I cannot open the .pdf file when the file downloaded. But other files open normal.

the message error as below:

"There was an error openning this document. the file is damaged could not be repaired"

But I open that file directly from server  is OK

private bool DownloadFile(string serverFolder, string fileName)


bool result = false;

string filePath = serverFolder + '\\' + fileName;if (System.IO.File.Exists(filePath))



Response.ContentType =
"application/octet-stream";if (System.IO.Path.GetExtension(fileName).ToLower().Equals("pdf"))


Response.ContentType =


"Content-disposition", "attachment; filename=\"" + fileName + "\"");



result =


return result;


3/25/2009 10:22:09 AM 93655 articles. 5 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 53

 Hi niemdamme,

Try to use the codee below and let us know if the problem still exists.

        FileStream MyFileStream;
        long FileSize;
        string path = Server .MapPath ( "~/svn-book.pdf" );
        MyFileStream = new FileStream ( path , FileMode .Open );
        FileSize = MyFileStream .Length;
        byte [ ] Buffer = new byte [ (int)FileSize + 1 ];
        MyFileStream .Read ( Buffer , 0 , (int)MyFileStream .Length );
        MyFileStream .Close ( );
        Response .ContentType = "application/pdf";
        Response .AddHeader ( "content-disposition" , "attachment; filename=MyReport.PDF" );
        Response .BinaryWrite ( Buffer );

Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers

3/26/2009 9:01:06 AM


I have tested on your source code.

but the error it still happen


3/31/2009 2:56:10 AM

Similar Artilces:

Problem with download large 25.0MB pdf file would not download on new beta from web server.
Name: Email: dgrayatfastkatdotcom Product: Firefox Summary: Problem with download large 25.0MB pdf file would not download on new beta from web server. Comments: Would not download PDF file from off site Server. Was 25.00mb file would only load 13.70MB Downloaded file with windows explorer. Tried 4X Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20100413 Firefox/3.6.4 (.NET CLR 3.5.30729) From URL: Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one yo...

How to File Upload and Download file ( .doc/.pdf/.gif/.exl) from server web browser C#
How to File Upload and Download file ( .doc/.pdf/.gif/.exl) from server web browser Please help me Thanking you Saikat   Uploading: Try a Google search for upload file web server c#. Download: <a href="">Download Me</a> HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question HiI want to download this logo.gif . It is possable to download. Download: <a href="">Download Me</a> and How to File Upload .doc/.pdf/.gif/.exl file we...

how to open .exe file in a web form in
hi, Are there any one who know to open .exe file from a web form application? make a link like: My Exe ...

Download / Open a Pdf File at Runtime from IIS Web Site
Hi Friends,   In my web application, i am generating the pdf dynamically at runtime and opening the same on a button click. This functionality is working perfectly when i am running my website from VS 2005. But the same application, when i am trying to access it from Localhost, i am not able to open/download the pdf. I am getting the ERROR: error opening destination file. I am using Response. I am using the following code: Response.ContentType = "Application/PDF" Response.AppendHeader("Content-Disposition", "attachment; filename=" & fil...

in how to open a file from file download prompt without asking user to save it or run it....just open it in internet explorer
I am designing a VB.NET based website I have a hyperlink, upon clicking on it a "File Download" prompt opens which asks me whether I want to "Save" the file, "Open"   But I want it to directly open in Internet Explorer without showing the prompt.... How can i do this? It should not show any prompt... when i click on the should directly open in a new IE window.... Thanks....   Try this  Response.AddHeader("Content-Disposition", "inline; filename=Log_" & activityLogID & ".xml") th...

add/change name/delete server files via web form
I have the add(upload) part of this page figured out. I have an application with an "Images" sub directory. I know how to access the getfiles() method from the system.IO namespace. I am using a while loop to create a table with an edit button (so that you can change the name of the file) and a delete button so you can remove the file from the server. Each file is on a new line much like it would look if it was bound to a datalist or datagrid. Here is where I am clueless. Can anyone point me in the right direction? I am not looking for someone to write this for me, beca...

ability to close page with open downloaded .doc or .pdf file and return to previous web page
 Hi: I have a grid with list of documents.  User selects one and this opens another page with the downloaded/open file.  Because this is not on a form, there is no return button/ link/ to the previous page with the grid.  One can use the browser back arrow but if you forget to do it that way, and try to just close the doc page, you close the web program.  Is there a way to do this, perhaps with ajax or some other new method such that if they close the document they will automatically return to the last page rather than close the ...

Visual Studio .NET cannot create or open the application. The likeliest problem is that required components are not installed on the local Web server. Run Visual Studio .NET setup and add the Web Deve
I installed Visual Studio .NET 2003 on Windows Vista Home Premuim, but I'm unable to select "Web Development" item from "Server Components" during the installation. I installed all the pre-requisits but I can not see Front Page Server Extention in the programs. I can see also the IIS. Appreciate if any one can guide me with the solution.   Thanks.   FPSE is not included with Vista, it's a separate download.  See for this. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. Tha...

Move File From Web Server to File Server
Our organization has a web server and file server in the same domain. On our public website ordering page, users have the ability to upload a document. The document is currently saved on the Web server in a temp directory. I need to move the uploaded file off the webserver and over to a specific directory on the file server. I have tried using File.Move to accomplish this but encountered permission errors. How does this need to be set up to work? The code format I have is File.Move ("c:\\dir\\file.ext", "\\\\fileserver\\dir\\file.ext"); Thanks in Advance ...

Downloading form. How to hide form after file is downloaded.
 Hi,I've this problem:I've form which user fills before downlaod file:<%= Resources.Resources.YourName %>*:<asp:Panel ID="_getInfoPanel" runat="server">  Your Name:<asp:TextBox ID="_yourNameTB" runat="server" /> ...<asp:Button ID="_addButton" runat="server"               Text="<%$ Resources:Resources, Continue %>" onclick="_addButton_Click" /> </asp:Panel> and when _addButton(in event h...

PDF download with web service generates error: file does not begin with '%pdf'
I get the following file when streaming a PDF file through a web service: file does not begin with '%pdf' I do not get this error with other files and I do not have this problem on the production server ironically just the staging server. Any ideas?...

Opening a File in a Web Form
Good Morning,I need some assistance with an assignement i need to accomplish the next couple of days. I need to in a web form select a file and have some informations about the file being visible by the code in the web form. What component can i use, or what classes to upload a file?? thks PipiMeiasAltas--Regarding this... PipiMeiasAltas wrote:...I need some assistance with an assignement i need to accomplish the next couple of days. I need to in a web form select a file and have some informations about the file being visible by the code in the web form. What component can i use, or w...

Downloads of pdf files do not open
Name: John Mactaggart Email: imactagatlineonedotnet Product: Firefox Summary: Downloads of pdf files do not open Comments: I have downloaded several pdf files and the open command in the download box does not work.You have to open the containg folder and open the file from there.Iam using Adobe reader 7.0 Browser Details: Mozilla/5.0 (Windows; U; Win95; en-US; rv: Gecko/20070219 Firefox/ ...

Opening files from a web form
Hey there, What I want to do is have  list box which displays all the files in a folder on the server and then the user can double click on them, or click on them and click a button and open them! atm I have the files displaying using   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim windir As String Dim file As String windir = ("C:\Inetpub\wwwroot\Fileviewtest\Data") Me.ListBox1.Items.Clear() Dim files() As String = Directory.GetFiles(windir) For Each file In files Me.ListBox1.Items.Add(System.IO.Path.GetFil...

Web resources about - Cannot open the file .pdf when downLoad from server -

Don't Download This Song - Wikipedia, the free encyclopedia
" Don't Download This Song " is the first single from "Weird Al" Yankovic 's 12th studio album Straight Outta Lynwood . The song was released ...

Facebook Adds To Download Your Information
Facebook increased the amount of information users can access when they download their account histories using the social network’s Download ...

Download the Facebook IQ digital magazine - Facebook for Business
The Facebook IQ digital magazine puts all the insights, best practices and key stats in one place. Download it on your mobile and read it anywhere. ...

Download previous versions of the Facebook for iOS SDK.

‘Silent updates’ for Android download latest version of Facebook without Google Play
... users to receive app updates without going through the Google Play store. Some Android users are now receiving “silent updates,” which download ...

Lifehacker, tips and downloads for getting things done
Lifehacker curates tips, tricks, and technology for living better in the digital age.

Technology Product Reviews, News, Prices & Downloads - - PC Magazine
PC Magazine is your complete guide to PC computers, peripherals and upgrades. We test and review computer- and Internet-related products and ...

Indie Music News, MP3 Downloads, Music Videos, Reviews - Stereogum
MP3s downloads, music videos, concert reviews, tour dates and contests. Updated regularly.

RN Download ThisShow (@RNDownload) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here RN Download ThisShow @ RNDownload ...

Kindle for iOS gets social sharing features, parallel downloads
... iOS app , making a number of changes to the mobile software. Chief among them are enhanced social features, as well as the ability to download ...

Resources last updated: 1/14/2016 5:16:39 PM