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

Document Library - SPFile.Item is null for copied files (Null when getting item from File)

$
0
0

Hi - 

We have a situation please assist with your expertise.

We are writing the custom code to copy file and assigning the ListItem properties into our "Sandbox" document library based on selected template from "Document_Template" document library. The "Sandbox" document library uses a custom content type.

1. Here we first copy the selected template file from "Document_Template" document library to our "Sandbox" document library

2. Then get the ListItem from the copied file into the "Sandbox" document library.

3. Modify the ListItem properties (fields) and assign proper permission on the ListItem of "Sandbox" document library

This process works like charm - 

We have created template of "Sandbox" document library by save as template, so that 1000+ Sandbox libraries can be created based on it.

Once we create new Sandbox library from the template, and try to create new document by selecting the template the process is failing at step 2 i.e. copied file item property is null

//Copies the file to the sandbox location from "Document_Template" document library
     selectedTemplateFile.CopyTo(sandboxUrl + selectedTemplateFile.Name);

//Get the list item from copied file and modify properties. 
     SPListItem sandboxDocumentItem = sandboxFileExist.ListItemAllFields;

or

   SPListItem sandboxDocumentItem = sandboxFileExist.Item;

Thanks in advance !!

Amit 


Viewing all articles
Browse latest Browse all 11571

Trending Articles



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