c#文件上传到服务器的方法,c# 通过文件流方式上传文件到服务器

时间:2025-03-01 07:08:30

public string UploadFile(string userID)

{

Byte[] MeaningFile;

FileStream stream = new FileStream(, , );

int size = Convert.ToInt32();

MeaningFile = new Byte[size];

(MeaningFile, 0, size);

();

FileStream fos = null;

string fileName = "";

string fileExt = (("."));

if (fileExt == ".xls")//必须是EXCEL文件

{

try

{

string filePath = ("~/DataFile/");

if (!(filePath))

{

(filePath);

}

fileName = userID + fileExt;

fos = new FileStream(filePath + fileName, , );

(MeaningFile, 0, );

();

}

catch

{

}

finally

{

if (fos != null)

{

try

{

();

}

catch

{

}

}

}

}

else

{

}

return fileName;

}