Search This Blog

Monday, February 13, 2012

Upload the Files in Sharepoint Using C#




public class insertdatademo : System.Web.UI.WebControls.WebParts.WebPart
{
public FileUpload file; 
}


 public insertdatademo()
        {
           
          file=new FileUpload();
        }


protected override void CreateChildControls()
{


file=new FileUpload();
            file.DataBind();
             this.Controls.Add(file);
            oButtonSubmit.Click += new EventHandler(oButtonSubmit_Click);


}


 void oButtonSubmit_Click(object sender, EventArgs e)
{




if(file.HasFile==true)
                {
                    SPAttachmentCollection attach = myListItem.Attachments;
                    String fileName = file.PostedFile.FileName;
                    byte[] textfile = file.FileBytes;
                    attach.Add(fileName, textfile);




                }
}


protected override void Render(HtmlTextWriter writer)
{


writer.Write("<table class='ms-formtoolbar' cellpadding='2' cellspacing='0' border='0' width='100%'><tr><td width='99%' class='ms-toolbar' nowrap><IMG SRC='/_layouts/images/blank.gif' width='1' height='18' alt=''></td><td class='ms-toolbar' nowrap='true'><TABLE cellpadding='0' cellspacing='0' width='100%'><TR><TD align='right' width='100%' nowrap>");
            file.RenderControl(writer);
            writer.Write("</TD></TR></TABLE></td></tr></table>");


}

No comments:

Post a Comment