Avatar of mohan21_kumar
mohan21_kumar asked on

How to attach file to the List in Sharepoint

Hi Experts,
   I'm new to sharepoint, I have a requirement where i have to attach a file to the List. I have tried to attach the file to the List using C#. But i'm getting Access denined as error message.
   I have written the following code to attach the file to the List. But i dont know how to give write permission to the Users
  I have enabled the anonymous access for the site in Central admin.

  Is there any other place where i have provide the permission or is it possible to provide permission to the User programmatically?

Please help me how to solve this or suggest me some URL or send me some sample code which would help me in solve this problem.

Thanks in advance
try
                    {
                        SPWeb web = SPContext.Current.Web;
                        web.AllowUnsafeUpdates = true;
                        
                        SPList list = SPContext.Current.Web.Lists["spforums_posts"];
 
                        
                        SPListItem listItem = list.Items[0];
                        string FileNameSave = MsgeInId + "_" + _btnUpload.FileName.ToString();
                        //Page.Response.Write(FileNameSave);
                        listItem.Attachments.Add(FileNameSave, _btnUpload.FileBytes);
                        listItem.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                    catch(Exception Ex)
                    {
                        Page.Response.Write("<center>" + Ex.Message.ToString() + "</Center>");
                        Page.Response.End();
                    }

Open in new window

Microsoft IIS Web ServerWindows Server 2003

Avatar of undefined
Last Comment
mohan21_kumar

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
cbueno

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
mohan21_kumar

Hi ,
  Thanks for your quick response.

   I have tried with this. but still it is giving the same problem. If you have the sample code can you please share it.


 
cbueno

Hi mohan
I never got around using something like this but there were plans.  So i dont have anything like that. Do a google serach for "sharepoint impersonating" or "moss impersonating", you should get a lot of samples. But if i were you i would check that the user that you are traying to impersonate can do this! Also did you check if there are any restrictions on the page ur traying to upload? DId you try and log in as the actual user you are impersonating and upload a file to the same site onto a different library and the same library and see if you get any errors/restrictions?
Regards
CB
ASKER
mohan21_kumar

Thanks for the solution
Your help has saved me hundreds of hours of internet surfing.
fblack61