views:

170

answers:

1

Hello, I am trying to upload a photo to a sharepoint library. If I use a relatively small file (370KB) then it works without any problems. But if I try to upload a file that is about 3MB large then I get the error: "Der Remoteserver hat einen Fehler zurückgegeben: NotFound." translated: "The remote server returned an error: NotFound."

I read that it should be possible to set the max message size, but I found no way to set such a thing in the ClientContext object.

This is the code I use:

    private void UploadFileCallback(object state)
    {
        var args = (List<object>)state;
        var itemContainer = (ISharepointItemContainer)args.ElementAt(0);
        var fileInfo = (FileInfo)args.ElementAt(1);

        var sharepointList = _context.Web.Lists.GetByTitle(itemContainer.ListName);
        Microsoft.SharePoint.Client.File uploadFile;
        FileCreationInformation newFile;

        using (FileStream fs = fileInfo.OpenRead())
        {
            byte[] content = new byte[fs.Length];

            newFile = new FileCreationInformation();
            int dummy = fs.Read(content, 0, (int)fs.Length);
            newFile.Content = content;
            newFile.Url = itemContainer.AbsoluteUrl + "/" + fileInfo.Name;
            uploadFile = sharepointList.RootFolder.Files.Add(newFile);
            _context.Load(uploadFile);
        }

        _context.ExecuteQuery();

        if (FileUploadCompleted != null)
        {
            FileUploadCompleted(this, EventArgs.Empty);
        }
    }

Does anyone have an idea on how to resolve this issue?

A: 

The first thing to try is to go to the Web Applications Management section in the Central Administration site for SharePoint. Select the General Settings for the web app that you are deploying to and increase the maximum upload size.

The second thing to try is to add this to your web.config:

<system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="52428800"/>
      </requestFiltering>
   </security>
</system.webServer>

This will let you set the size to something larger.

Ryan Hayes
Hello,thanks for the answer. I will try it tomorrow and let You know if it worked...
Manfred Ramoser
Did it end up working or was it something else?
Ryan Hayes
Hello, sorry for the delay, I verified the setting in central administration and it is set to 50 MB. But the error arises already with files of 3 MB! I tried also to add your xml to the web.config but without success. But is the Web.config used by Sharepoint? Because this silverlight application runs within a silverlight web part...
Manfred Ramoser

related questions