I am uploading doucment using object model. However my 'UploadFile()' method throws exception "The request failed with HTTP status 403: Forbidden.". This happens if my current user is not a member of one custom group (ABCGroup). And 'ABCGroup' has all permissions. Even if I give 'Full Control' permissions to this user it doesn't work. So I am really wondering.
2 Answers
As you are trying to upload files through code, did you try to use the RunWithElevatedPrivileges method ? Below is a link which will give you more information on the method.
http://msdn.microsoft.com/en-us/library/bb466220(office.12).aspx
You can do something like this:
SPSite siteColl = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate() {
using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID)) {
using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID)) {
////Add your code to upload the file here....
}
}
});
I assume you are adding the document through the UploadFile()
method to a document library. So make sure the user who is uploading the document has permission to the document library. No need to use RunWithElevatedPrivileges
.