Embed
Email

Attachments in SharePoint

Document Sample

Shared by: xiuliliaofz
Categories
Tags
Stats
views:
0
posted:
11/5/2011
language:
English
pages:
6
Attachments in SharePoint

This example demonstrates how a file, uploaded through a file upload control is added as an attachment to

a list item.



using (SPSite oSPsite = new SPSite(http://website Url/))



{



using (SPWeb oSPWeb = oSPsite.OpenWeb())



{



oSPWeb.AllowUnsafeUpdates = true;







// Fetch the List



SPList list = oSPWeb.Lists["MyList"];







// Get the List item



SPListItem listItem = list.GetItemById(1);







// Get the Attachment collection



SPAttachmentCollection attachmentCollection = listItem.Attachments;







Stream attachmentStream;



Byte[] attachmentContent;







// Get the file from the file upload control



if (this.fileDocAttach.HasFile)



{



attachmentStream = this.fileDocAttach.PostedFile.InputStream;

attachmentContent = new Byte[attachmentStream.Length];







attachmentStream.Read(attachmentContent, 0, (int)attachmentStream.Length);







attachmentStream.Close();



attachmentStream.Dispose();







// Add the file to the attachment collection



attachmentCollection.Add(this.fileDocAttach.FileName, attachmentContent);



}







// Update th list item



listItem.Update();







oSPWeb.AllowUnsafeUpdates = false;



}



}









DeepuPau wrote:







Customized form not working with attachment



22-Nov-07







Hi

I have created a Custom list form throgh Sharepoint Designer 2007.When I am



trying to upload an attachment through the newform or Edit form I am getting



an error "The form has customized not working with attachement".



Please provide any quick solution to overcome this issue.







Thanks



Deepu Paul







Previous Posts In This Thread:







On Thursday, November 22, 2007 6:57 AM



DeepuPau wrote:







Customized form not working with attachment



Hi







I have created a Custom list form throgh Sharepoint Designer 2007.When I am



trying to upload an attachment through the newform or Edit form I am getting



an error "The form has customized not working with attachement".



Please provide any quick solution to overcome this issue.







Thanks



Deepu Paul







On Monday, November 26, 2007 2:21 PM



Tom Scheifler wrote:

No quick solution



There is no quick solution. In fact, there I have not been able to confirm that any of the proposed solutions

actually work.







But here is a link to a lengthy discussion on the topic.







http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1104194&SiteID=1







On Tuesday, November 27, 2007 12:25 AM



DeepuPau wrote:







Hi Tom Thanks for the reply.



Hi Tom







Thanks for the reply. I resolved the problem by with out customizing the web



part, now I am hiding the fields in the web part using content type, So that



I can able to attach the files.







Thanks



Deepu Paul









"Tom Scheifler" wrote:







On Tuesday, November 27, 2007 8:23 AM



Cornelius J. van Dyk [MVP] wrote:

Have you tried the reverse by creating the list and attachment field from the



Have you tried the reverse by creating the list and attachment field



from the browser and then customizing it in SPD to see if that works?







--



Thanks



C



Blog: http://www.cjvandyk.com/blog



RSS: http://feeds.feedburner.com/cjvandyk



SPCAP - SharePoint Capacity Planning Tool



http://www.cjvandyk.com/blog/aspx/SPCap.aspx









"Deepu Paul" wrote in message



news:C3669667-EE4F-485D-8C8E-E6F153020BAB@microsoft.com:







On Wednesday, January 23, 2008 1:55 PM



furfooos wrote:







Hi Deepu PaulThanks a lot for this post. it helped me soooo muchthanks.



Hi Deepu Paul







Thanks a lot for this post. it helped me soooo much

thanks.



--



Love You All









"Deepu Paul" wrote:







On Monday, May 12, 2008 11:21 AM



Rao Gorpade wrote:







The form has customized not working with attachement



Hi,







I have created a Custom list form throgh Sharepoint Designer 2007.When I am trying to upload an

attachment through the newform or Edit form I am getting an error "The form has customized not working

with attachement".Please provide any quick solution to overcome this issue.







Thanks









Submitted via EggHeadCafe - Software Developer Portal of Choice



Measuring SharePoint Page Rendering



http://www.eggheadcafe.com/tutorials/aspnet/c0a9ac9e-53cd-442f-8981-9d5f236c2be5/measuring-

sharepoint-page.aspx



Related docs
Other docs by xiuliliaofz
Dreaming
Views: 2  |  Downloads: 0
Maurice White BDSc Melb
Views: 0  |  Downloads: 0
article-7901
Views: 0  |  Downloads: 0
Application - City of Laramie
Views: 0  |  Downloads: 0
Project Outline - TeacherWeb
Views: 0  |  Downloads: 0
NSSE EDUCATION
Views: 0  |  Downloads: 0
me344_f03
Views: 0  |  Downloads: 0
Experiment_11a
Views: 0  |  Downloads: 0
CHAPTER 16
Views: 0  |  Downloads: 0
Distributed Data Base Systems
Views: 3  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!