Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET table Word
I'm using Visual Web Developer 2008. I have an asp:Table in ASP.NET and I could Export that Table to .doc (Word 97-2003) formats. But when Exporting to Word 2007 (.docx), Export is success with .docx extension. That file cannot open using Word 2007, but can open in Word-2003. When trying to open in Word-2007 one Error message saying that "Cannot Open, Invalid file content" (like that).
 
The code I'm giving here for your reference.
 
If anybody can help me pls.....
 
Thanks in advance.
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"       
Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.docx")
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.Charset = ""
EnableViewState = False
 
Dim writer As New System.IO.StringWriter()
Dim html As New System.Web.UI.HtmlTextWriter(writer)
Table1.RenderControl(html)
Response.Write(writer)
Response.End()
Posted 23-Jun-11 1:53am
Edited 23-Jun-11 2:28am
v2
Comments
pcksalim at 25-Jun-11 6:52am
   
Hai All,
 
I done It by changing UTF7 to UTF8 to get Proper .DOC file openable in Word2007 too.
 
Thank you very much.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just save the html as a .doc file, and Word will open it. By the way, you want to use Response.WriteFile() versus Response.Write().
  Permalink  
Comments
pcksalim at 24-Jun-11 2:22am
   
Hai All and Mr. John Simmons,
 
Thank you very much for your reply, time and considerations.
 
I couldnt implement Response.WriteFile() in the above codelines, pls inform one example with above given code, bcs Response.WriteFile() need ("String Filename") and I already given filename=WORK_ORDER.docx" and I tried as Response.WriteFile("WORK_ORDER.docx"), but it is not supporting.
 
I decided not to go for .docx, since Proper .doc is sufficient in Word 2007.
In systems with Word2003, I could open Exported html-DOC(.doc) file and could SaveAs proper .doc file. Then it can Open in Word2007 too.
 
Unfortunately my client using Word2007 only and in systems with Word2007, My Export with Response.Write(Writer) gives no proper readable html content to SaveAs .doc, but showing unreadable Text like below:
 
+ADw-table id+AD0AIg-Table1+ACI- cellspacing+AD0AIg-0+ACI- cellpadding+AD0AIg-1+ACI- align+AD0AIg-Center+ACI- bordercolor+AD0AIgAj-000099+ACI- border+AD0AIg-0+ACI- style+AD0AIg-color:+ACM-000099+ADs-background-color:White+ADs-border-color:+ACM-000099+ADs-border-width:2px+ADs-border-style:Double+ADs-font-weight:bold+ADs-width:100+ACUAOw-border-collapse:collapse+ADsAIgA+- +ADw-tr
 

I will be Satisfied with the below code If it can Open "readable htm-doc" content in Word2007 also (Now openable in Word2003) which can SaveAs Proper .doc file. The code given below:
 
Response.Clear()
Response.Buffer = True
Response.ContentType = "Application/msword"
Response.AddHeader("Content-Disposition","attachment; filename=WORK_ORDER.doc")
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.Charset = ""
EnableViewState = False
 
Dim writer As New System.IO.StringWriter()
Dim html As New System.Web.UI.HtmlTextWriter(writer)
Table1.RenderControl(html)
Response.Write(writer)
Response.End()
 
This code also Not providing "readable htm-doc content in Word2007"
 
If anybody can help me pls.....
 
Thanks in advance.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hai All,
 
I done It by changing UTF7 to UTF8 to get Proper .DOC file openable in Word2007 too.
 
Thank you very much.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 25 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100