Unable to view uploaded documents in Sharepoint Meeting Workspace

This is something interesting. I’ve found this while I was developing an event management app. So apparently I was selected the Meeting Workspace Site Definition. The problem occurs when I was uploading a document to a document library. In here we can’t use SPFile.CopyTo();  So I used

SPSite site = SPContext.Current.Site;

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile("/Shared%20Documents/Doc.docx");
using (SPWeb oWeb = site.OpenWeb(<siteURL>))
{
    SPList documentLibrary = meetingWorkspace.Lists["Document Library"];
    documentLibrary.RootFolder.Files.Add(file.Name, file.OpenBinary());
}
This code works fine, no issues. But if  you navigate to the document library, you can not NOT SEE any uploaded documents there(in view).  So what was happened to the document?  If you check the value of the SPList.RootFolder.Files.Count;  property you will see that the file is there too. So why does the Document Library keep saying that there are no items to display?
Here is the answer.
By default you can associate a Meeting Workspace with multiple Calendar Items. Every time you associate a Meeting Workspace with a Calendar Item, a new instance is being registered with the Meeting Workspace. In order to separate files that belong to different instances, SharePoint uploads them to separate folders. The confusing thing is, that although the instance folders are not being displayed in the UI, they are there.
So all we have to do is make sure to add the document into correct instance. Following is the workaround,

SPSite site = SPContext.Current.Site;

SPWeb web = SPContext.Current.Web;
string instanceId = "1";
SPFile file = web.GetFile("/Shared%20Documents/Doc.docx");
using (SPWeb meetingWorkspace = site.OpenWeb(<siteURL>))
{
    SPList documentLibrary = meetingWorkspace.Lists["Document Library"];
    SPFolder instanceFolder = documentLibrary.RootFolder.SubFolders[instanceId];
    instanceFolder.Files.Add(file.Name, file.OpenBinary());
}
Now Go back to the Library and check. Check this for more clarifications.
Good luck.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s