Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have this client OM code to add a new file in a doc.lib.:

        clientContext.ExecuteQueryAsync(
            (o, args) =>
            {
                var fileCreationInformation = new FileCreationInformation();
                fileCreationInformation.Content = System.Text.Encoding.Unicode.GetBytes(reportContent);
                fileCreationInformation.Overwrite = true;
                var uploadLocation = string.Format("{0}/{1}", reports.RootFolder.ServerRelativeUrl, title + STR_Extension);
                fileCreationInformation.Url = uploadLocation;                    
                Microsoft.SharePoint.Client.File newFile = reports.RootFolder.Files.Add(fileCreationInformation);

                ListItem newItem = newFile.ListItemAllFields;
                clientContext.Load(newItem);
                clientContext.Load(newFile);

                clientContext.ExecuteQueryAsync(
                    (o1, args1) =>
                    {

...

When context client have Full control permissions or Design permissions is working perfect. But I get Exception when user have only Contribute permissions to doc.lib. Of course I can create a new report or upload a new report using the browser, but the code is not working in this case.

Any clue ?

Thank you

share|improve this question
add comment

2 Answers 2

A couple things to look at.

Can you remove:

ListItem newItem = newFile.ListItemAllFields;
clientContext.Load(newItem);

I don't think they do anything in this context...you'd use these after you uploaded the file to get the list item reference if you were adding metadata.

I'm also not sure I understand the point of the dual ExecuteQueryAsync calls. You could minimally convert the 2nd one to ExecuteQuery as you're already in an async context with the 1st one:

clientContext.ExecuteQuery();

Not sure if changing either of these would address your permissions issues, but it may.

share|improve this answer
    
Hi, thanx for tip with single ExecuteQueryAsync, you are right. I did test by removing the ListItem load but that didn't change. See the answer next. –  Ovidiu Becheş-Puia Jul 30 '11 at 21:57
add comment
up vote 0 down vote accepted

I did find the issue: the file getting added is a html report, but to allow user to see in browser the content of the file without downloading it (which is the def. action for html files on SP) I was changing the extension of the file from .html to .aspx :). Is working ok until the user doing the report has only contribute permission on doc.lib. In this case SP denies upload of aspx files. So the fix was to set the extension to html instead of aspx :)

Thanx again Rob.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.