.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Reading/writing Word documents - keeping formatting

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

I've done some reading about reading from and writing to a Word doc. The reading from worked without issue:

string strPath = "Test.doc";
FileStream fStream = new FileStream
    (strPath, FileMode.Open, FileAccess.Read);
StreamReader sReader = new StreamReader(fStream);
string text = sReader.ReadToEnd();

But of course this is just a string, without any formatting information included. Writing to the document using a StreamWriter worked, but I received errors when opening the document.

I've also read that trying to perform actions on an Office document on a server without the Office products installed on it can result in mayhem. I'm working on a MVC application that will allow users to upload documents to the server, work on them, save their work and email it around. That doesn't specifically require the need to read/write programmatically, but for certain application functions I do need this. Any helpful suggestions are appreciated.

View Complete Post

More Related Resource Links

Reading and Writing Images From a Windows Mobile Database using UltraLite 10(C#)

Periodically I get a request for information on how to read and write binary data to a database running on Windows Mobile. If you search the Internet you can typically find examples that are available on Windows Desktops or allow you to read and write to a local file system. The problem is that it can take a bit of work to get this code to work on Windows Mobile accessing a database.

Ultimately you might be asking, why would I want to store and image in a database? Well in an environment where you synchronizing data between a local mobile database and a consolidated (central) database this can be extremely useful. Imagine if an insurance adjuster went to an accident scene, took a picture of a damaged car, loaded it into his Windows Mobile database and then replicated that image up to the Insurance headquarters for approval. All of this could be done in a very short period of time when using images in the database. Another good example might be a doctor who was waiting for a patient chart to become available. If you could store the image in a database this chart could be sent down to the doctor's device once it became available.

For this article I am not going to get into how to synchronize the images to and from a remote and central database as this is typically fairly straightforward when using a data synchronization technologies like MobiLink

XML Reading and Writing

We learned to process XML files using the Document Object Model as implemented by the XmlDocument class. To go further and make XML friendlier, the .NET Framework provides many other classes for different purposes, allowing you to create and manage nodes from custom .NET classes.
Besides the XmlDocument and the derived classes of XmlNode, the .NET Framework provides the XmlTextWriter class, which is derived from XmlWriter. The XmlTextWriter class works in a top-down approach to create, or deal with, the contents of an XML file. This class writes an XML node and moves down without referring

Office Services: Merging Word Documents on the Server Side with SharePoint 2010


Office 2010 and SharePoint 2010 include a new set of components called Application Services. These put a rich set of tools in a developer's bag for Office automation. We'll show you how to use Office OpenXML, Word Automation Services and SharePoint to build a simple application that merges separate status reports into a single document.

Manvir Singh, Ankush Bhatia

MSDN Magazine July 2010

Beyond Macros: Create Word and Excel Smart Documents with C++ and XML


One of the coolest new parts of Office 2003 is a programmability feature called Smart Documents, which allows developers to augment Word and Excel documents with programmable content and behavior. Typically, examples illustrating Office programmability use Visual Basic or Visual Basic .NET. In this article, the author develops a Smart Document for Excel using C++. He describes the new ISmartDocument interface and shows how to use it to manage a simple task list such as an Excel spreadsheet.

Mike Kelly

MSDN Magazine December 2003

Can I search Office Documents (Excel, Word etc) in WSS 3.0 without having to install MS Office?



Does WSS 3.0 come with the filters for searching MS Office Documents or do you have to have MS Office installed on WSS 3.0 Server?



Assembling Documents on SharePoint 2010 Sites by Merging Content from Excel, PowerPoint, and Word

This article describes a rich document assembly solution that takes Word 2010 documents, Excel 2010 documents, and PowerPoint 2010 documents and merges them together to form a final report in Word. It does all of this from a SharePoint 2010 Web Part.

Converting Word Documents to PDF using SharePoint Server 2010 and Word Services (Visual How To)

Watch the video and explore code as you learn how to programmatically convert Word documents to PDF format on the server by using Word Automation Services with SharePoint Server 2010.

Sample: Converting Word Documents to PDF using SharePoint Server 2010 and Word Automation Services

Explore the code in this visual how-to article as you learn how to programmatically convert Word documents to PDF format on the server by using Word Automation Services with SharePoint Server 2010.

Video: Converting Word Documents to PDF Format Using SharePoint Server 2010 and Word Services

Watch this visual how-to video as you learn how to programmatically convert Word documents to PDF format on the server by using Word Automation Services with SharePoint Server 2010. (Length: 6:15)

How to use SharePoint Server 2007 SP2 to compare documents without opening one by one in Word ? (ver

Hi All, How to use / access the versiondiff.apsx feature ? I'm using SharePoint 2007 SP2 Enterprise but somehow i cannot use that features like in this website said: http://www.ssw.com.au/ssw/Standards/BetterSoftwareSuggestions/SharePointTeamServices.aspx for example: here's my document library - http://mossdev01/Correspondence/Forms/AllItems.aspx Diff - http://mossdev01/Correspondence/versiondiff.aspx --> FAILED 404 ? Any kind of help and suggestion would be greatly appreciated. Thanks, Albert/* Infrastructure Support Engineer */

how to open force SharePoint 2010 to open documents withint the browser instead of invoking word app

guys, when user clicks on the word document within a document library, it opens up in the word IDE , how can i change this so that documents opens up in the browser. the "Library settings\ advanced settings\ open documents in the browser" setting is set to "open in the browser"   thanks sameer

Converting Word Documents library to PDF document library in SharePoint Server 2007

My project requires me to create an event reciever such that when a word file is added to one library the same content pdf file should be added to other library also when a word file is updated,edited or checked in the respective pdf file in other document library should be replaced by a new pdf file with the edited word content . Can we do this in Sharepoint 2007 I have seen this can be done in Sharepoint 2010 http://msdn.microsoft.com/en-us/library/ff181518.aspx

SharPoint 2010 : Open word and excel documents within Browser without installing office Web App on S

guys, SharePoint 2010 how can i have the word documents and excel sheets open up with in the browse windows without installing Office Web App on the server, all i want to give users is the read access. Also i did not install anyting on sharepoint server to have pdf open up in the browser and yet it does. thanks in advance. sameer   thanks sameer

Writing to a Word Doc from my ASP.Net form

Hello, I am trying to write some HTML content to a Word doc using my ASP.Net form. I have code in place using Microsoft.Office.Interop.Wordwhich generates the doc but when I specify the text, i.e. <strong>Something</strong>, it comes through literally, not bolded. How do I get formatted text (HTML) into a Word doc? Here's what I got:   object oMissing = System.Reflection.Missing.Value; ApplicationClass wordApp = new ApplicationClass(); Document wordDoc = wordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); Paragraph para = wordDoc.Paragraphs.Add(ref oMissing); para.Range.Text = "<strong>SAMPLE HERE</strong>"; para.Range.InsertParagraphAfter(); object fileName = "c:\\test.doc"; wordDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wordDoc.Close(ref oMissing, ref oMissing, ref oMissing); wordApp.Quit(ref oMissing, ref oMissing, ref oMissing); Thanks,  

need to compare two word 2007 documents using openxml

 Hi,Can some one help me, how to compare two word 2007 documents using openxml and c#. I need to change color for the differences in the compared document. Plz suggest some thing here ....Thanks,Ramakrishna

how to disable Editing of word documents in browser



sharepoint 2010
installed Office Web app

i installed office word apps and integrated it with sharepoint 2010 and all the office documents now open in the browser. but this also give the qualified users permissions to edit the word document in the browser, something that i dont want to do right now. can someone tell me how i can disable the "Edit in Browser" button that shows up on the word documents after it open in the browser.



Reading AND Writing Access 2 databases with SSIS


I went for a job interview this morning, and one of the scenarios that the IT manager (a former programmer) told me about was the following .... If anyone could give me any pointers that I can email him pointers to tomorrow (Wednesday 22nd) it may just help tip his decision in my direction. So there's beer in it if you answer a relevent answer, and I get the job.

Old systems using Access 2 databases. These systems are not due to be updated any time soon.

New systems need access to that data, so each night he exports information using SSIS. However, he needs to also write data back, and more often than just overnight.

However, when he connects to the database, using ODBC connections I think, he says that the app (SSIS) opens the tables / database exclusively, even if he selects the option NOT to open it exclusively.

Any ideas, suggestions or comments ?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend