c# post 接收传来的文件

时间:2023-03-09 16:36:53
c# post 接收传来的文件
private void UploadFile()
{
//
//......其他代码
//
HttpFileCollection files = HttpContext.Current.Request.Files;
if(files.Count>)
{
int lintTemp = files[].FileName.LastIndexOf(".");//得到input标签中的file文件路径;
string lstrFileType = string.Empty;
string lstrContentType = string.Empty;
if(lintTemp!=- &&files[].FileName.Length>lintTemp+)
{
lstrFileType = files[].FileName.Substring(lintTemp+).ToUpper();
}
if(lstrFileType.ToUpper()=="JPG")
{
if(files[].ContentLength<)
{
//记得要先保存到应用程序发布所在的服务器上!
files[].SaveAs(Server.MapPath("~/Files/")+"JPG1."+files[].FileName.Substring(files[].FileName.LastIndexOf(".")));
}
}
}
//
//......其他代码
//
}

c# post 接收传来的文件