private string SaveFileToLocal(string url)
{
FileStream os = null;
FileStream ns = null;
try
{
string savePath = @"C:\Users\Administrator\MyCopy";
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
string fileName = Path.GetFileName(url);
string fileFullPath = Path.Combine(savePath, fileName);
os = new FileStream(url, FileMode.Open);
ns = new FileStream(fileFullPath, FileMode.OpenOrCreate);
byte[] tempBuffer = new byte[4096];
int bytesRead = 0;
do
{
bytesRead = os.Read(tempBuffer, 0, tempBuffer.Length);
ns.Write(tempBuffer, 0, bytesRead);
} while (bytesRead > 0);
return fileFullPath;
}
catch (Exception e)
{
throw new Exception("保存文件出错,原因:"+e.Message);
}
finally
{
ns.Close();
os.Close();
}
}