Custom Upload Webpart for Sharepoint

Using this code you can create a custom webpart where you can define the upload functionality for ur sharepoint document library.

The document library where the documents have to go in can be define in the custom properties. any queries you can ping me back and

more functionalities are coming soon, enjoy

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Xml.Serialization;
using System.IO;
using System.Drawing;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls;
using System.Web;
using System.Text;
using System.Collections;
namespace UploadResume
public class UploadResumeCustomProperty : System.Web.UI.WebControls.WebParts.WebPart
#region Variable Declaration
private Button btnupload;
private Label lblMessage;
private HtmlInputFile inputFile;
private string _DoclibName;
[WebBrowsable(true), Category(“WebPart Settings”), WebDisplayName(“Choose Your Document Library”),
WebDescription(“Choose your document library name where you want to upload the documents”),
public string DoclibName
get { return _DoclibName; }
set { _DoclibName = value; }
#region Create Child Control
protected override void CreateChildControls()
#region labelShow
this.lblMessage = new Label();
this.lblMessage.ID = “_lbltext”;
this.lblMessage.Text = “Upload”;
#region inputfile
this.inputFile = new HtmlInputFile();
this.inputFile.ID = “_fileUpload”;
#region  Button
this.btnupload = new Button();
this.btnupload.ID = “_btnupload”;
this.btnupload.Text = “Upload”;
this.btnupload.Click += new EventHandler(btnupload_Click);
#region Add Controls
#region button click upload
private void btnupload_Click(object sender, EventArgs e)
byte[] byt = new byte[Convert.ToInt32(inputFile.PostedFile.ContentLength)];
using (SPSite objSite = new SPSite(SPContext.Current.Site.Url.ToString()))
using (SPWeb objWeb = objSite.OpenWeb())
SPFolder mylibrary = objWeb.Folders[this._DoclibName];
objWeb.AllowUnsafeUpdates = true;
mylibrary.Files.Add(System.IO.Path.GetFileName(inputFile.PostedFile.FileName), byt);
catch (System.Exception ex)
lblMessage.Text = ex.ToString();

Leave a Reply

Your email address will not be published. Required fields are marked *