Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello every body. i am new for creating word documents in asp.net .what my problem is i have content in my database when i clink button in windows application the data content will need to display in one word document. how can i do it.can any body help me to solve my problem.


thanks in advance!.
Posted
Comments
Prerak Patel 19-Jan-12 1:48am    
Windows application in ASP.Net?!!

You need to use word automation to accomplish your task
Add reference of com object "Microsoft.office.interop.word"
here is good article you can use following links,
office automation with c#.net[^]
office automation: by MSDN[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jan-12 2:46am    
Prasad, the problem is this: of course you can manipulate Word document as such on the server side as much as you want. But how to show in on a Web page? Look at the question: it is about ASP.NET.
--SA
Sergey Alexandrovich Kryukov 19-Jan-12 3:02am    
So, I added my answer to explain this most principle part of the problem and explained how the solution should look -- please see.
I credited your answer but decided not to vote this time.
--SA
The answer by Prasad can give you the idea on how to work with Word documents on the server side, so what? How can you show the Word document on the Web page. The problem looks like this: the Word document formats are proprietary and not standard. Not every client system provides the means of rendering Word documents. There are no systems which can do it by default, not only in some Web browser — in any way. This is because Microsoft Word (and Microsoft Office in general) is commercial software. This is directly opposite to the principles of WWW which is build around open standards.

So, the quick answer is: Word documents do not belong in the word of the Web.

This is not very satisfying though. Word documents became a part of real life, so there is a number of sites which allow to upload Word document in the formats of most versions and view or even edit it on the screen of the Web browser in a way very similar to some simplified processor of the Word documents (typical example: job search sites like Dice or Monster). How to do this?

The answer is: no matter what you do, on the Web page you need to present an HTML document (or even HTML editor) the way resembling a Word document. You will need to develop mapping of the Word document (more realistically, some reasonable and perhaps pretty modest subset of the Word features) and re-write everything into HTML with style having a Word document and this mapping on input.

I would say, you would be wise to keep internal format to HTML. Alternatively, if could be a special XML format mapped to HTML+CSS or XML with XSLT transformation through XSLT style sheet (http://en.wikipedia.org/wiki/XSLT[^]).

And for transformation you will need to read/parse a Word document internally, so this is where you can use Office interop as Prasad advised.

Good luck,
—SA
 
Share this answer
 
Your questions is confusing.
First you say
i am new for creating word documents in asp.net
and then you say
i have content in my database when i clink button in windows application
, so is it ASP.NET application or Windows application?

You can use Microsoft C# Word Automation for Windows application if you have Microsoft Office installed.
For ASP.NET application Microsoft C# Word Interop is not recommended by Microsoft - http://support.microsoft.com/kb/257757.
Instead you can try using this ASP.NET Word component like in this code:
C#
// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create a new empty document.
DocumentModel document = new DocumentModel();

// Add document content.
document.Sections.Add(
  new Section(document, 
    new Paragraph(document, "Hello World!")));

// Microsoft Packaging API cannot write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
using (MemoryStream documentStream = new MemoryStream())
{
  document.Save(documentStream, SaveOptions.DocxDefault);

  // Stream file to browser.
  Response.Clear();
  Response.ContentType = "application/vnd.openxmlformats";
  Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx");

  documentStream.WriteTo(Response.OutputStream);

  Response.End();
}
 
Share this answer
 

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