Question : 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
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
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("
" + Ex.Message.ToString() + "
"); Page.Response.End(); }
Open in New Window Select All

Answer : How to attach file to the List in Sharepoint

Hi Mohan21

I think you may have to loo into impersonating via code in sharepoint!
http://www.sharepointblogs.com/tanujashares/archive/2007/08/07/impersonation-in-sharepoint-2007.aspx
http://www.sharepoint-tips.com/2007/03/impersonation-in-event-handlers.html
http://spsfactory.blogspot.com/2007/02/sharepoint-webparts-impersonation-and.html

Also you may want to see if the location where the file is (if excel) is trusted? That could be an issue too i think.

Goodluck
CB
Random Solutions  
 
programming4us programming4us