0

In my application i have to save the result in the form of a text file in a folder.My code is

 using (HttpWebResponse result = (HttpWebResponse)request.GetResponse())
                {    
                    using (Stream stream = result.GetResponseStream())
                    {
                        Response.ContentType = "application/octet-stream";
                        Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"", "result." + GetExtension(exportFormat)));

                        var length = copyStream(stream, Response.OutputStream);
                        Response.AddHeader("Content-Length", length.ToString());
                    }
                }

When this code is executed a dialog box is shown which has save and cancel options in it.

But the problem is that i have to save the result in a specific folder in the form of text file (which is obtained from this code in dialog) without showing the dialog box.

mck
  • 978
  • 3
  • 14
  • 38

2 Answers2

0

It's your browser that is popping up that dialogue box.

Try forcing the content disposition header to .txt:

Content-Disposition: attachment;filename=\"file.txt\"

(On phone, not tested)

nimeshjm
  • 1,665
  • 10
  • 13
-1

I'm assuming it's the list of found files you're wanting to save to a text file, how about this on your save event (rough code so not extensively tested)?

using (FileStream fs = new FileStream("c:\\files.txt", FileMode.Create, FileAccess.Write))
{
    using (StreamWriter sw = new StreamWriter(fs))
    {
        foreach (string item in lstFilesFound.Items)
        {
            sw.WriteLine(item);
        }
    }
}

Try Dis..

Vishnu
  • 33
  • 3
  • 13
  • If you [copy an answer](http://stackoverflow.com/questions/14120668/how-to-write-a-text-file-from-this-output), at least link to it. – CodeCaster Jun 24 '14 at 07:55