Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am facing a problem. i want to create a csv file from db. but i don;t want to download this file. i want to save this into particular location like (@"D:\output.xml").
how i achieve this.

What I have tried:

C#
var response = System.Web.HttpContext.Current.Response;
            response.BufferOutput = true;

            //clear response
            response.Clear();
            response.ClearHeaders();
            response.ContentEncoding = Encoding.Unicode;

            //For Csv Export give file name
            string filename = string.Format("{0}", DateTime.Now.ToString("g").Replace("/", "-").Replace(":", "_").Replace(" ", "-"));
            response.AddHeader("content-disposition", "attachment;filename=MailMergeLog-" + filename + ".CSV ");
            response.ContentType = "text/plain";
            response.Write(sb.ToString());
            response.End();


but this code directly download this but i want to save this file somewhere in my system.
Posted
Updated 30-Jun-16 2:59am
Comments
NagaNimesh 11474558 30-Jun-16 7:58am    
see u r saying that autodownload once file is completed so remove those "response code " try and let me know

1 solution

If you want to save the file to a particular location on the server, then you need to use the classes from the System.IO namespace to save the file, and not send it to the client.

If you want to control where the file is saved on the client, then you're out of luck. You cannot control where, or even if, the file is saved on the client. If you could, that would be a major security vulnerability.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900