Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Generating word document and saving to a particular location in c#.net

Generating word document and saving to a particular location in c#.net

Scheduled Pinned Locked Moved ASP.NET
csharphelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YazhiniP
    wrote on last edited by
    #1

    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

    C Y 2 Replies Last reply
    0
    • Y YazhiniP

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • Y YazhiniP

        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

        Y Offline
        Y Offline
        YazhiniP
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups