downloading works in MSVC but not in IIS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m.a

    downloading works in MSVC but not in IIS

    Hello,

    I have a web page that when user clicked on a button, it would create a
    send a file to use so he can save it on his computer.

    The code that I wrote is as follow:



    protected void DownloadBtn_Cli ck(object sender, EventArgs e)

    {

    string FileNameNoSpace = "test_file.ext" ;

    string FilePathName = Server.MapPath( @"DownloadTemp\ " + FileNameNoSpace );

    CreateFile( FilePathName);

    FileInfo TargetFile = new FileInfo(FilePa thName);

    Response.Clear( );

    Response.Conten tType = "applicatio n/octet-stream";

    Response.AddHea der("Content-Disposition", "attachment ; filename=" +
    TargetFile.Name );

    Response.AddHea der("Content-Length", TargetFile.Leng th.ToString());

    Response.WriteF ile(TargetFile. FullName);

    Response.End();

    }

    void CreateFile(stri ng Route_key, string FilePathName)

    {

    TextWriter tw = new StreamWriter(Fi lePathName);

    // write a line of text to the file

    tw.WriteLine("t his file created on" + DateTime.Now);

    for (int i = 0; i < 1000; i++)

    {

    tw.WriteLine("s ome data could be added here (line = "+i.ToString()+ ")");

    }

    // close the stream

    tw.Close();

    }



    when I run this code in MSVC, it works correctly. After I pressed DownLoad
    button, I get a save dialog and i can save the generated file but when I am
    doing the same in IIS, after clicking the Download button, I will get a
    blank screen.

    Any help appreciated.



    Regards


Working...