我已经创建了一个WCF方法,它将根据传递的输入流创建一个文件。第一次调用该方法时,它会创建没有任何问题的文件。下次时间调用会导致路径被拒绝访问...任何帮助解决问题。
wcf函数如下
public void UploadFile1(RemoteFileInfo1 request)
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;
request.FilePath = "\\" + request.FilePath;
if (!Directory.Exists(request.FilePath))
{
Directory.CreateDirectory(request.FilePath);
}
string filePath = Path.Combine(request.FilePath, request.FileName);
using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
//read from the input stream in 6K chunks
//and save to output stream
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
}
request.filepath是共享驱动器位置