Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Programatically Create List Item in Meeting workspace document library folder

$
0
0

Hi,

First off here is the structure of my site

- Root site
     - Meeting Workspace
          - Meeting Documents Library (with a content type using a word document template)
               - Folder 1
               - Folder 2
               etc..

The requirement..
When a new SPFolder, like Folder 1, is created within the Meeting Document library, an event receiver creates a new list item based off the content type, into the folder. This means it will use the content type document template and put a physical word document into that folder.

The problem
I receive a System.IO.DirectoryNotFoundException when I try to save the file to that location. 

The weird part is it works 100% when it runs on a document library OUTSIDE of the meeting workspace, i.e. directly under the root site - but when the library is INSIDE the meeting workspace it gives this error. Here is my code...

private static void CreateFile(SPFolder newfolder, SPFile file)
{
	Stream readStream = file.OpenBinaryStream();
	SPFile uploadedFile = newfolder.Files.Add(newfolder.Url + @"/" + "Meeting Minutes.docx", readStream, true);
	uploadedFile.CheckOut();

	SPListItem listitem = uploadedFile.Item;

	listitem["Title"] = "Meeting Minutes";
	listitem.Update();

	uploadedFile.Update();
	uploadedFile.CheckIn(string.Empty);
}

In the exception message I can copy out the URL of the folder, paste it in my browser and it successfully gets there, so the URL I am passing it is definitely valid.

If anyone has experienced this I would appreciate some help!

Thanks!



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>