Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4118060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:54:44+00:00 2026-05-20T22:54:44+00:00

I am trying to load the template file my SPDocumentLibrary has set, do some

  • 0

I am trying to load the template file my SPDocumentLibrary has set, do some transforms in OpenXML then save it back to the library as a document. I think I have all the steps down except reading the template. I don’t know the “correct” way to open it (I could just use a WebClient to download it but it makes me feel dirty just typing that). Here is what I have so far.

public string GetOrGenerateChecklist(string PracticeName, string ContractID, string EducationDate, string MainContactInfo, string Address)
{
    using (SPWeb web = SPContext.Current.Web)
    {
        SPDocumentLibrary list = (SPDocumentLibrary)web.Lists["Educator Checklists"];
        var templetAddr = String.Concat(web.Url, '/', list.DocumentTemplateUrl);
        SPQuery query = new SPQuery();
        query.Query = string.Concat(
                                //Snip
                                   );
        var items = list.GetItems(query);
        //if document exists return existing document.
        if (items.Count > 0)
            return String.Concat(web.Url, "/Educator Checklists/", PracticeName, " - ", ContractID, ".docx");

        MemoryStream documentStream;

        //copy the stream to memory
        using (Stream tplStream = ????????) //<-------   my problem
        {
            documentStream = new MemoryStream((int)tplStream.Length);
            CopyStream(tplStream, documentStream);
            documentStream.Position = 0L;
        }
        using (WordprocessingDocument template = WordprocessingDocument.Open(documentStream, true))
        {
            template.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
            MainDocumentPart mainPart = template.MainDocumentPart;
            mainPart.DocumentSettingsPart.AddExternalRelationship(
                "http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate",
                new Uri(templetAddr, UriKind.Absolute));

            ReplaceText(mainPart, "#PracticeName#", PracticeName);
            ReplaceText(mainPart, "#EducationDate#", EducationDate);
            ReplaceText(mainPart, "#MainContactInfo#", MainContactInfo);
            ReplaceText(mainPart, "#Address#", Address);
        }
        documentStream.Position = 0L;
        list.RootFolder.Files.Add(String.Concat(PracticeName, " - ", ContractID, ".docx"), documentStream);

        return String.Concat(web.Url, "/Educator Checklists/", PracticeName, " - ", ContractID, ".docx");
    }

}

So my question is how do i get the template stored at templetAddr loaded in to the memory stream?

Also I am fairly new to sharepoint so if you see any other big mistakes I have made please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:54:44+00:00Added an answer on May 20, 2026 at 10:54 pm
    web.GetFile(templetAddr).OpenBinaryStream() 
    

    http://msdn.microsoft.com/en-us/library/ms476063.aspx (SPWeb.GetFile)

    http://msdn.microsoft.com/en-us/library/ms470901.aspx (SPFile.OpenBinaryStream)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, Django is telling me the template I'm trying to load doesn't
Trying to load content into a div, then on click load the previous content
Trying to load a small .txt file into mysql but get all my data
I trying to load and save setting with this code but when I closing
I'm trying to load data from xml-file with TinyXML (c++). int height = rootElem->attrib<int>(height,
I'm trying to run a T4 template that opens a XML file and uses
Effectively I'm trying to send some template emails so that I can test a
I'm trying to load a file using webrequest method. First I need to log
I'm trying to load in the jQuery template plugin using jQuery.getScript, but even though
I am trying to load a css file to the homepage only in drupal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.