c# code
-------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void btnAdd_Click(object sender, EventArgs e)
{
if (upImage.HasFile)
{
if (CheckFileType(upImage.FileName))
{
String filePath = "~/UploadImages/" + upImage.FileName;
upImage.SaveAs(MapPath(filePath));
}
}
}
bool CheckFileType(string fileName)
{
string ext = Path.GetExtension(fileName);
switch (ext.ToLower())
{
case ".gif":
return true;
case ".png":
return true;
case ".jpg":
return true;
case ".jpeg":
return true;
default:
return false;
}
}
void Page_PreRender()
{
string upFolder = MapPath("~/UploadImages/");
DirectoryInfo dir = new DirectoryInfo(upFolder);
dlstImages.DataSource = dir.GetFiles();
dlstImages.DataBind();
}
}
Design
at the end you need to create folder in Application root called "UploadImages" to store images on it.
0 التعليقات:
إرسال تعليق