<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Open a word processing document for read-only access</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Open%2520a%2520word%2520processing%2520document%2520for%2520read-only%2520access/</link><description>Recent changes to Open a word processing document for read-only access</description><atom:link href="https://sourceforge.net/p/asposeopenxml/wiki/Open%20a%20word%20processing%20document%20for%20read-only%20access/feed.rss" rel="self"/><language>en</language><lastBuildDate>Tue, 26 May 2015 13:02:00 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/asposeopenxml/wiki/Open%20a%20word%20processing%20document%20for%20read-only%20access/feed.rss" rel="self" type="application/rss+xml"/><item><title>Open a word processing document for read-only access modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Open%2520a%2520word%2520processing%2520document%2520for%2520read-only%2520access/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -49,4 +49,4 @@

 ## Download ##

-* [Sample Code]()
+* [Sample Code](http://sourceforge.net/projects/asposeopenxml/files/Aspose.Words%20Vs%20OpenXML/OpenReadOnlyAccess.zip/download)
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Tue, 26 May 2015 13:02:00 -0000</pubDate><guid>https://sourceforge.netef8d3bfe0c18405f8f4c743621fb176b20f530ea</guid></item><item><title>Open a word processing document for read-only access modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Open%2520a%2520word%2520processing%2520document%2520for%2520read-only%2520access/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Sometimes you want to open a document to inspect or retrieve some information, and you want to do so in a way that ensures the document remains unchanged. In these instances, you want to open the document for read-only access. &lt;/p&gt;
&lt;h2 id="openxml-words"&gt;OpenXML Words&lt;/h2&gt;
&lt;p&gt;The below sample code shows how you can add some text and attempt to save the changes to show that access is read-only. Once you have access to the body of the main document part, you add text by adding instances of the &lt;strong&gt;Paragraph, Run, and Text&lt;/strong&gt; classes. This generates the required &lt;strong&gt;WordprocessingML&lt;/strong&gt; markup. &lt;/p&gt;
&lt;p&gt;Below is the code sample&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    OpenWordprocessingDocumentReadonly(OpenReadOnly.docx);
    public static void OpenWordprocessingDocumentReadonly(string filepath)
    {
        // Open a WordprocessingDocument based on a filepath.
        using (WordprocessingDocument wordDocument =
            WordprocessingDocument.Open(filepath, false))
        {
            // Assign a reference to the existing document body.  
            Body body = wordDocument.MainDocumentPart.Document.Body;

            // Attempt to add some text.
            Paragraph para = body.AppendChild(new Paragraph());
            Run run = para.AppendChild(new Run());
            run.AppendChild(new Text("Append text in body, but text is not saved       
            OpenWordprocessingDocumentReadonly"));

           }
    }
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="asposewords"&gt;Aspose.Words&lt;/h2&gt;
&lt;p&gt;Make the &lt;strong&gt;Document&lt;/strong&gt; object having parameter filename and LoadOptions without setting password we cant protect or open document for read-only access . &lt;strong&gt;LoadOptions&lt;/strong&gt; is a shortcut to initialize a new instance of this class with the specified password to load an encrypted document. Then initialize the &lt;strong&gt;DocumentBuilder&lt;/strong&gt; object which provides methods to insert text, images and other content, specify font, paragraph and section formatting of word document. &lt;/p&gt;
&lt;p&gt;Below is the sample code&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    OpenWordprocessingDocumentReadonly(OpenReadOnly.docx);
    private static void OpenWordprocessingDocumentReadonly(string fileName)
    {
        //make object of document class to get the filename and set the password
        Document doc = new Document(fileName, new LoadOptions("1234"));
        //intialize document builder to insert text in word document
        DocumentBuilder db = new DocumentBuilder(doc);
        string txt = "Append text in body - OpenAndAddToWordprocessingStream";
        db.Writeln(txt);
       //save the document file
        doc.Save(OpenReadOnly.docx);
    }
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="download"&gt;Download&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="../"&gt;Sample Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Mon, 25 May 2015 19:29:57 -0000</pubDate><guid>https://sourceforge.neta502ccf297bb51f3eca84fdf88f10df54355255a</guid></item></channel></rss>