上传文件,另存为物理文件方法

public bool UploadImg( byte [] fileBytes, string path)
{
try
{
// 文件保存目录路径
String savePath = " /upload/ " ;
String dirPath
= Server.MapPath(savePath);

FileInfo ff
= new FileInfo(dirPath + path);
if ( ! ff.Directory.Exists) Directory.CreateDirectory(ff.DirectoryName);
System.IO.FileStream fs
= System.IO.File.Create(dirPath + path);
fs.Flush();
fs.Write(fileBytes,
0 , fileBytes.Length);
fs.Close();
fs.Dispose();
return true ;
}
catch
{
return false ;
}
}

你可能感兴趣的:(上传文件)