Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i try to upload document on sharepoint 2010 site using c#.net but it give me error "the remote server returned an error (403) forbidden"
i use below code for perform this operation:
C#
public void UploadDocument(string siteURL, string documentListName,string documentListURL, string documentName,byte[] documentStream)
        {
            try
            {
                using (ClientContext clientContext = new ClientContext(siteURL))
                {
                    //Get Document List
                    Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);
                    var fileCreationInformation = new FileCreationInformation();
                    //Assign to content byte[] i.e. documentStream
                    fileCreationInformation.Content = documentStream;
                    //Allow owerwrite of document
                    fileCreationInformation.Overwrite = true;
                    //Upload URL
                    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("i:0#.f|sqlmembers|admin", "admin@!23", "CS-avr-01");
                    ClientContext context = ClaimClientContext.GetAuthenticatedContext(siteURL);
                    fileCreationInformation.Url =documentListName + "//" + documentListURL;
                    Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
                        fileCreationInformation);
                    //Update the metadata for a field having name "DocType"
                    uploadFile.ListItemAllFields["DocType"] = "Favourites";
                    uploadFile.ListItemAllFields.Update();
                   clientContext.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
           }          
        }

--so any idea or anything wrong in my code i login on site as a administrator and when i upload document manually it upload successfully but give error when upload using code.
- i try many solution but all time i gate same error.
-any one have any idea about this please help me.
-thank you.
Posted
Updated 6-Jun-13 4:09am
v3
Comments
tumbledDown2earth 6-Jun-13 5:03am    
did you check if your server accepts post/put requests from. Also check you are authorised or not
Ahmed Bensaid 6-Jun-13 10:36am    
Hello,
What do you have in your SP logs ?
bhavesh002 7-Jun-13 3:52am    
hi...i solved this problem thank you
vimal1 17-Jul-13 5:40am    
please share your resolution
harishgajawada 4-Sep-17 7:47am    
please let us know how you solved the problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900