本文介绍了上载垂直扩展名的文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我想上传一个垂直分机.使用asp上载按钮的文件,是否可以通过javascript或c#代码后面的任何方式,或通过其他任何方式在用户单击浏览按钮时通过他/她看到要上传的垂直扩展名的文件.
Hello everyone,I want to upload a perticular ext. file using asp upload button,is there any way either by javascript or c# code behind or anything else via which when user clicks on browse button,he/she should only see files of that perticular extension to upload.
推荐答案
if (fileUploadCategoryImage.HasFile == true)
{
categoryImageName = fn_UploadCategoryImage(fileUploadCategoryImage);
}
public string fn_UploadCategoryImage(FileUpload UploadedFile)
{
HttpPostedFile file = UploadedFile.PostedFile;
string fileExt = Path.GetExtension(file.FileName).ToLower();
string fileName = Path.GetFileName(file.FileName);
if (fileName != string.Empty)
{
try
{
if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
{
str = DateTime.Now.ToFileTime() + "_" + fileName;
file.SaveAs(Server.MapPath("~/admin/Upload/Category/") + str);
}
}
catch (Exception ex)
{
throw ex;
}
}
//str = fileName;
return str;
}
这篇关于上载垂直扩展名的文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!