HttpPostedFile f = File1.PostedFile;//这个知道是什么吧
string FileName = GetUniquelyString(); //获取一个不重复的文件名
string FileOrginName = f.FileName.Substring(f.FileName.LastIndexOf("\\") + 1);//获取文件的原始名
if (f.ContentLength > 0)
{
String postFileName;
String FilePath = Server.MapPath(".\\photo").ToString();
string path = FilePath + "\\";
try
{
int pos = f.FileName.LastIndexOf(".") + 1;
postFileName = f.FileName.Substring(pos, f.FileName.Length - pos);
f.SaveAs(path + FileName + "." + postFileName); //存储指定的文件到指定的目录
}
catch (Exception exec)
{
throw (exec);
}
double unit = 1024;
string fpname = FileOrginName.Remove(FileOrginName.Length - postFileName.Length - 1);
视频文件上传
最新推荐文章于 2025-07-01 15:43:32 发布
本文介绍了一个使用 HttpPostedFile 对象进行文件上传,并通过 GetUniquelyString 获取唯一文件名的过程。详细步骤包括从请求中获取文件,提取原始文件名,处理文件大小限制,存储文件到服务器指定目录,以及处理异常情况。同时,展示了如何移除文件扩展名后的部分字符串。
4838

被折叠的 条评论
为什么被折叠?



