Generating word document and saving to a particular location in c#.net
-
Hi, I have to generate a word document dynamically in .Net. I have to write the contents of the GridView to the Word document. I am able to do all but,the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box. Can anyone please tell me that how to store the word file automatically to a particular location? I have given the code below. string attachment = "attachment; filename=" + strFilePath; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-word"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvRCA.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End();
Yazhini
-
Hi, I have to generate a word document dynamically in .Net. I have to write the contents of the GridView to the Word document. I am able to do all but,the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box. Can anyone please tell me that how to store the word file automatically to a particular location? I have given the code below. string attachment = "attachment; filename=" + strFilePath; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-word"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvRCA.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End();
Yazhini
YazhiniP wrote:
the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box.
You should never tell the client yes, unless you know enough about what you're doing, to know that it's possible. In this case, it's not possible. Imagine if it was, if every website could just put files into your file system without asking you first.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
Hi, I have to generate a word document dynamically in .Net. I have to write the contents of the GridView to the Word document. I am able to do all but,the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box. Can anyone please tell me that how to store the word file automatically to a particular location? I have given the code below. string attachment = "attachment; filename=" + strFilePath; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-word"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvRCA.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End();
Yazhini
ok...I dropped the idea of using Response object.I tried using FileStream and StreamWriter.but,how to pass the GridView object to the StreamWriter? FileStream fs = File.Create(path); fs.Close(); StreamWriter sw = new StreamWriter(path); StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvRCA.RenderControl(htwWriter); sw.Write(htwWriter); sw.Close(); The above code writes only System.Web.UI.HtmlTextWriter to the word file. I am beginner in .Net and i dont know a lot. Do u have any idea on how to do this?. Thanks in advance... :)
Yazhini