我上传文件并将其转换为字节并将其保存在数据库中。它在我的本地系统中正常工作。但我将它托管在专用服务器中,它无法将路径转换为字节。它显示一个错误
'找不到路径'C:\fakepath\1003.pdf'的一部分。
代码:
//byte[] bContent = myWebClient.DownloadData(@strFileUploadSubSplit[3]);
byte[] bContent = null;
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(strFileUploadSubSplit[3].ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
// get total byte length of the file
long _TotalBytes = new System.IO.FileInfo(strFileUploadSubSplit[3].ToString()).Length;
// read entire file into buffer
bContent = _BinaryReader.ReadBytes((Int32)_TotalBytes);
// close file reader
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
string base64String = System.Convert.ToBase64String(bContent, 0, bContent.Length);
str = strFileUploadSubSplit[0] + "*" + strFileUploadSubSplit[1] + "*" + strFileUploadSubSplit[2] + "*" + base64String ;
string URL = "http://dev2.weicorp.com:81/IApp.svc/IApp/Doc";
string ret = string.Empty;
var webRequest = System.Net.WebRequest.Create(URL) as HttpWebRequest;
byte[] byteArray = Encoding.UTF8.GetBytes(str);
webRequest.Method = "POST";
webRequest.ContentType = "application/octet-stream";
webRequest.ContentLength = byteArray.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
dataStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
ret = reader.ReadToEnd();
string status = ret.ToString();
context.Response.Write(status);