The File Upload Control
The following properties give you flexible ways to access the uploaded file:
File Bytes The file is exposed as a byte array.
File Content The file is exposed as a stream.
Posted File The file is exposed as an object of type Http PostedFile. This object has properties, such as Content Type and Content Length.
Methods
Save as()
Program
using System.IO;
public partial class _Default : System.Web.UI.Page
{
string Uppath;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Visible = false;
Uppath = Server.MapPath(“~/MyUploads");
if (!Directory.Exists(Uppath))
{
Directory.CreateDirectory(Uppath);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fname = FileUpload1.FileName;
string dpath = Server.MapPath(“~/MyUploads");
string concate = dpath + "//" + fname;
FileUpload1.SaveAs(concate);
lblContent.Text = "Content Type:" + FileUpload1.PostedFile.ContentType;
lblFname.Text = "File Name is:" + fname;
lblsize.Text = "File size in byte is:" + FileUpload1.PostedFile.ContentLength;
lblPath.Text = "File save at location:" + concate;
lblExtension.Text = Path.GetExtension(fname);
} else
{
Label1.Visible = true;
Label1.Text = "Please select a file to upload";
}
}
}
Upload Multiple file
The following properties give you flexible ways to access the uploaded file:
File Bytes The file is exposed as a byte array.
File Content The file is exposed as a stream.
Posted File The file is exposed as an object of type Http PostedFile. This object has properties, such as Content Type and Content Length.
Methods
Save as()
Program
using System.IO;
public partial class _Default : System.Web.UI.Page
{
string Uppath;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Visible = false;
Uppath = Server.MapPath(“~/MyUploads");
if (!Directory.Exists(Uppath))
{
Directory.CreateDirectory(Uppath);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fname = FileUpload1.FileName;
string dpath = Server.MapPath(“~/MyUploads");
string concate = dpath + "//" + fname;
FileUpload1.SaveAs(concate);
lblContent.Text = "Content Type:" + FileUpload1.PostedFile.ContentType;
lblFname.Text = "File Name is:" + fname;
lblsize.Text = "File size in byte is:" + FileUpload1.PostedFile.ContentLength;
lblPath.Text = "File save at location:" + concate;
lblExtension.Text = Path.GetExtension(fname);
} else
{
Label1.Visible = true;
Label1.Text = "Please select a file to upload";
}
}
}
Upload Multiple file
No comments:
Post a Comment