~~~~~~上午发了贴了,但高手们回答的太糊了,有的提供的网上的参考例子根本没用!现在50分,一次性付,那位能帮我解决这两个问题的:
1、用c#实现图片上传到目录(目录可以指定,也可以程序自动生成),但在上传时要能判断上传文件的类型,只能上传图片,jpg.gif.png等,其他不可以,上传到一个目录就行,如果能生成缩略图最好
2、用c#实现图片上传数据库,是access数据库,上传时要能判断上传文件的类型,只能上传图片,jpg.gif.png等,其他不可以请高手们提供源码吧,最好是源码,能用就行,叫我从网上参考资料,没用的,也许我太菜了。公司做人才求职时,上传个人照片用的,那个高手帮我解决了,今天就可以放假了,谢谢你们了,高手们!
1、用c#实现图片上传到目录(目录可以指定,也可以程序自动生成),但在上传时要能判断上传文件的类型,只能上传图片,jpg.gif.png等,其他不可以,上传到一个目录就行,如果能生成缩略图最好
2、用c#实现图片上传数据库,是access数据库,上传时要能判断上传文件的类型,只能上传图片,jpg.gif.png等,其他不可以请高手们提供源码吧,最好是源码,能用就行,叫我从网上参考资料,没用的,也许我太菜了。公司做人才求职时,上传个人照片用的,那个高手帮我解决了,今天就可以放假了,谢谢你们了,高手们!
{
//遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
DateTime dt=DateTime.Now;
string strPath=System.Configuration.ConfigurationSettings.AppSettings["uploadpath"].ToString();
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
HttpPostedFile postedFile = files[iFile];
string fileName,linkName;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
// System.IO.Stream imgdatastream = postedFile.InputStream;
// int imgdatalen = postedFile.ContentLength;
// byte[] imgdata = new byte[imgdatalen];
// int n = imgdatastream.Read(imgdata,0,imgdatalen);
DataTable tmpDt=(DataTable)ViewState["filesDt"];
DataRow dr=tmpDt.NewRow();
dr[0]=fileName;
dr[1]=Session["ID"].ToString()+"_"+dt.Year+dt.Month+dt.Day+dt.Hour+dt.Minute+dt.Second+System.IO.Path.GetExtension(fileName);
linkName=dr[1].ToString();
tmpDt.Rows.Add(dr);
ViewState["filesDt"]=tmpDt; //实现上传
string pathStr=strPath+linkName;
if (System.IO.Directory.Exists(strPath))
{
postedFile.SaveAs(pathStr);
}
else
{
System.IO.Directory.CreateDirectory(strPath);
postedFile.SaveAs(pathStr);
}
// this.fileName.Value+=fileName+";";
// this.linkName.Value+=linkName+";";
//邦定文件列表
this.binderDrgFiles();
WebCommon.ShowMsg(this,"附件上传成功");
}
else
WebCommon.ShowMsg(this,"请选择要上传的文件");
}
}
catch(Exception err)
{
WebCommon.ShowMsg(this,err.Message);
}
}
string fileName;
if(uploadfile.PostedFile != null && uploadfile.PostedFile.FileName.Length > 0)
{
string destDir = Server.MapPath("UploadFile");
try
{
string sExtension;
string[] aDangerExtension = {".jpg",".gif",".png"};
sExtension = Path.GetExtension(uploadfile.PostedFile.FileName);
bool flag=false;
foreach(string sTemp in aDangerExtension)
{
if (sExtension.ToLower() == sTemp.ToLower())
{
flag=true;
break; }
}
if(flag==false)
{
//不允许上传的格式
return;
}
Random oRan = new System.Random();
fileName =
DateTime.Now.Year.ToString() +
DateTime.Now.Month.ToString() +
DateTime.Now.Day.ToString() +
DateTime.Now.Hour.ToString() +
DateTime.Now.Minute.ToString() +
DateTime.Now.Second.ToString() +
oRan.Next(9999).ToString() +
sExtension;
uploadfile.PostedFile.SaveAs(Path.Combine(destDir,fileName));
}
catch (Exception exc)
{
}
}