HMJING
**过程虽可贵,结果价更高**

public void Up()
{
UploadFile("jing",@"D:\11.xls");
}

public ActionResult UploadFile(string userID, string path)
{
Byte[] MeaningFile;
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
int size = Convert.ToInt32(stream.Length);
MeaningFile = new Byte[size];
stream.Read(MeaningFile, 0, size);
stream.Close();
FileStream fos = null;

string fileName = "";
string fileExt = path.Substring(path.LastIndexOf("."));
if (fileExt == ".xls" || fileExt == ".xlsx")//必须是EXCEL文件
{
try
{
string filePath = Server.MapPath("~/DataFile/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
fileName = userID + fileExt;
fos = new FileStream(filePath + fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fos.Write(MeaningFile, 0, MeaningFile.Length);
fos.Close();
}
catch
{
}
finally
{
if (fos != null)
{
try
{
fos.Close();
}
catch
{
}
}
}
}
else
{

}
return RedirectToAction("UpLoad");
}

posted on 2015-11-30 10:19  HMJING  阅读(1019)  评论(0编辑  收藏  举报