Click here to Skip to main content
14,878,254 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get the path after downloading a word document in button click in c#

What I have tried:

private void download_character_certificate_word(string str_content_type, string memo_body, string school_id, string base_url)
            StringBuilder str = new StringBuilder();
            Response.ContentType = str_content_type;
            Response.Charset = "";
            switch (str_content_type)
                case "application/":
                    Response.AddHeader("Content-Disposition", "attachment; filename=Study_Certificate.xls;");
                case "application/msword":
                    Response.AddHeader("Content-Disposition", "attachment; filename=Study_Certificate.doc;");
                default: break;
            StringBuilder sbResponseString = new StringBuilder();
            string wordHeader = "<html xmlns:o=''urn:schemas-microsoft-com:office:office'' ";
            wordHeader += "xmlns:w=''urn:schemas-microsoft-com:office:word'' ";
            wordHeader += "xmlns=''''> ";
            wordHeader += "<head><title>Document Title</title>";
            wordHeader += "<!--[if gte mso 9]><xml><w:WordDocument><w:View>Print</w:View><w:Zoom>100</w:Zoom>";
            wordHeader += "<w:DoNotOptimizeForBrowser/></w:WordDocument></xml><![endif]-->";
            wordHeader += "<style> @page Section1 {size:8.2in 11.6in; mso-first-footer:ff1; mso-footer: f1; mso-header: h1; ";
            wordHeader += " padding:2.0pt 1.5pt 1.5pt 1.5pt; border:0pt;";
            wordHeader += "margin:1.0in 0.8in 1.0in 0.8in ; mso-header-margin:0.1in; ";
            wordHeader += "mso-footer-margin:0.1in; mso-paper-source:0;} ";
            wordHeader += "div.Section1 {page:Section1;} p.MsoFooter, li.MsoFooter, ";
            wordHeader += "div.MsoFooter{margin:0in; margin-bottom:0pt; ";
            wordHeader += "mso-pagination:widow-orphan; tab-stops:center 1.0in right 1.0in; ";
            wordHeader += "font-size:9.0pt; font-family:'Arial';} ";
            wordHeader += "p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0in; ";
            wordHeader += "margin-bottom:0pt; mso-pagination:widow-orphan; tab-stops:center ";
            wordHeader += "0.2in right 0.2in; font-size:8.0pt; font-family:'TimesNewRoman';}--></style></head>";
            string wordBody = "<body><div class=Section1>" + str.ToString() + "</div></body></html>";//
Updated 7-Feb-21 19:54pm

1 solution

What path?
You don't have a source path - because you are building a "document" and sending it to the client so there is no file involved at your end.
You can't get a client path because you have no control at all over what happens to the data once you have sent it to the client - his browser may save it or display it, that's up to it and the user browser settings but even if it is saved, you can't find out where for security reasons.

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