DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Open a file using asp.net (http://www.daniweb.com/forums/thread114651.html)

apkumar Mar 19th, 2008 2:00 am
Open a file using asp.net
 
Hi all,

I would like to open a file in Local drive using Asp.net,

And I have written the following code in user control which could open the file,

Response.AddHeader("Content-Disposition", "attachment; filename=" & strFilename)
Response.WriteFile("C:\\open\\" & strFilename)
Response.Flush()
Response.Close()

The above code working fine in .Net 2005, In SharePoint also I am able to open the file, But After opening the file I am unable to do Any operation in that page, I can do any operation once I refresh the page....

Any Suggestions???

Kindly revert back to me if u have concerns...


Thanks in Advance,

kumar.

serkansendur Mar 19th, 2008 3:46 am
Re: Open a file using asp.net
 
 string fileName = @"C:\deneme.txt";
        StreamReader sr = File.OpenText(fileName);
        while (sr.Peek() != -1)
        {
            Response.Write(sr.ReadLine() + "<br>");
        }
        sr.Close();

plazmo Mar 19th, 2008 1:54 pm
Re: Open a file using asp.net
 
you cant do any more writing to the page once you close the response. There is really no reason to close the response anyways.

also, if all you are sending is the file to be saved then use Response.TransmitFile


All times are GMT -4. The time now is 4:08 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC