Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How to  create a SharePoint web part using File upload control.give example?
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace LoisAndClark.WPLibrary
{
public class MYWP : WebPart
{
FileUpload objFileUpload = new FileUpload();
protected override void CreateChildControls()
{
this.Controls.Add(new System.Web.UI.LiteralControl
("Select a file to upload:"));
this.Controls.Add(objFileUpload);
Button btnUpload = new Button();
btnUpload.Text = "Save File";
this.Load += new System.EventHandler(btnUpload_Click);
this.Controls.Add(btnUpload);
}
private void btnUpload_Click(object sender, EventArgs e)
{
string strSavePath = @"C:	emp";
if (objFileUpload.HasFile)
{
string strFileName = objFileUpload.FileName;
strSavePath += strFileName;
objFileUpload.SaveAs(strSavePath);
}
else
{
//otherwise let the message show file was not uploaded.
}
}
}
}

REPLY :
using System; using System.Collections.Generic; using System.Text; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using Microsoft.SharePoint.WebPartPages; namespace LoisAndClark.WPLibrary { public class MYWP : WebPart { FileUpload objFileUpload = new FileUpload(); protected override void CreateChildControls() { this.Controls.Add(new System.Web.UI.LiteralControl ("Select a file to upload:")); this.Controls.Add(objFileUpload); Button btnUpload = new Button(); btnUpload.Text = "Save File"; this.Load += new System.EventHandler(btnUpload_Click); this.Controls.Add(btnUpload); } private void btnUpload_Click(object sender, EventArgs e) { string strSavePath = @"C: emp"; if (objFileUpload.HasFile) { string strFileName = objFileUpload.FileName; strSavePath += strFileName; objFileUpload.SaveAs(strSavePath); } else { //otherwise let the message show file was not uploaded. } } } } 
Replied By: Name: Rajesh Kumar