Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi
I want to save the exported file in a particular path with Specific name format showing data and time

What I have tried:

C#
protected void ExportToExcel(object sender, EventArgs e)
        {
            gvDetails.AllowPaging = false;
            this.bind();
            Response.ClearContent();
            
            Response.AddHeader("content-disposition", "attachment; filename=Name.xls");
            Response.ContentType = "application/excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gvDetails.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

        }
Posted
Updated 7-Apr-17 1:20am
Comments
Karthik_Mahalingam 7-Apr-17 6:58am    
in client machine?
Member 12605293 7-Apr-17 7:07am    
No
Karthik_Mahalingam 7-Apr-17 7:08am    
then ? what is the actual question
Member 12605293 7-Apr-17 7:08am    
I need to update the file on daily basis so if I have date and time it is helpful for me
Karthik_Mahalingam 7-Apr-17 7:10am    
your question is to export the file with specific date time stamp?

1 solution

string fileName = "Name";
            string dateFormat = "MMMddYYYY"; // the format which you want to display
            string outPutFileName =  string.Format("{0}_{1}.xls",fileName,DateTime.Now.ToString(dateFormat));
            Response.AddHeader("content-disposition", "attachment; filename=" + outPutFileName);
 
Share this answer
 
Comments
Member 12605293 7-Apr-17 7:55am    
Hi Karthik
Thanks :) I have made the below code it is showing time as well
 protected void ExportToWord(object sender, EventArgs e)        {            gvDetails.AllowPaging = false;            this.bind();            Response.ClearContent();            string fileName = "Name";            string dateFormat = "MMddyyyy";            string timeformat = "HHmmss";            string outPutFileName = string.Format("{0}_{1}_{2}.xls", fileName, DateTime.Now.ToString(dateFormat), DateTime.Now.ToString(timeformat));            Response.AddHeader("content-disposition", "attachment; filename=" + outPutFileName);                        //Response.AddHeader("content-disposition", "attachment; filename=Name.doc");            Response.ContentType = "application/word";            System.IO.StringWriter sw = new System.IO.StringWriter();            HtmlTextWriter htw = new HtmlTextWriter(sw);            gvDetails.RenderControl(htw);            Response.Write(sw.ToString());            Response.End();        }
Member 12605293 7-Apr-17 7:57am    
Is that possible to save in a particular location by Saving file using SaveFileDialog ???

Karthik_Mahalingam 7-Apr-17 8:02am    
No, you cannot access client machine.
SaveFileDialog is supported in windows app
Member 12605293 7-Apr-17 8:04am    
ok karthik. Whether I can do in my machine?
Karthik_Mahalingam 7-Apr-17 8:27am    
I am not sure, give a try and let me know.

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