Attached document from code behind does not show up in CMS Administration

Manmath Kulkarni asked on March 8, 2017 12:11


I am attaching text file to root page from code behind. Also I am able to fetch the file using attachment URL.

string jsondata = "somejsondata";
using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/" + CurrentSite.SiteName + ".txt"), false)){
        _testData.WriteLine(jsondata); // Write the file.

//Attach txt file to root page
string filepath = Server.MapPath("~/" + CurrentSite.SiteName + ".txt");
    DocumentAttachment attachment = DocumentHelper.GetAttachment(rootPage, CurrentSite.SiteName +             ".txt", false);
    if (attachment != null)
        DocumentHelper.DeleteAttachment(rootPage, attachment.AttachmentGUID);
        DocumentHelper.AddAttachment(rootPage, "FileAttachment", filepath);
 catch (Exception ex){}

This attachment is not visible in CMS administration dashboard. RootPage -> Properties -> Attachment

Kindly help.


Recent Answers

Chetan Sharma answered on March 8, 2017 12:55

Hi Manmath,

Few important things:-

  1. Are you using any sort of workflow? If that's the case then you may have to Use WorkflowManager and use checkout and check in to have an effect.

The example that you have used (I could be wrong) here works well with Page fields where you need to pass the field GUID where you want it to attach. Since you are attaching it to root->properties I don't know how it will work. However, please verify #1 before looking into this

Did you consider using this REST API to send attachments - Manipulating data using REST

Thanks, Chetan

0 votesVote for this answer Mark as a Correct answer

Peter M answered on March 8, 2017 13:54

If you want to see your attachment in the attachment tab you should use use

DocumentHelper.AddUnsortedAttachment(rootPage, "FileAttachment", filepath);

There are two types of attachments:

  • Unsorted - added via the Properties -> Attachments tab; using this approach, you can easily add attachments to any document; all attachments added this way are taken as one group and displayed together using the web parts
  • Grouped - added by defining a 'Document attachments' field for a document type and then uploading a file on a document's Form tab; for each Document attachments field, you can have an unlimited number of files attached; you can also define more fields of this type to have several groups of attachments which can be displayed separately on the live site
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.