求助,从本机获取文件上传到服务器上取不到正确路径问题
protected void FileUpload()
{
string webPathFile = Server.MapPath(Request.Url.AbsolutePath);//该处始终取得不到服务器的正确路径,求解???
webPath = webPathFile.Substring(0, webPathFile.LastIndexOf("\\") + 1) + "EXCEL" + "\\";
for (int x = 0; x <ListExcelName.Items.Count;x++ )
{
FileUpload(ListExcelName.Items[x].Text.ToString(), webPath);
}
}
public void FileUpload(string localPathFile, string webPhysicalPathFile)//localPathFile是本地物理文//件 webPhysicalPathFile是服务器物理路径
{
FileStream inStream = null;
FileStream outStream = null;
try
{
string fileName = localPathFile.Substring(localPathFile.LastIndexOf("\\") + 1);
//读取本地文件流
inStream = File.OpenRead(localPathFile);
string file = webPhysicalPathFile + fileName;//得到网络服务器的文件路径名;
outStream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write);
byte[] bytes = new byte[4096];
int start = 0;
int length;
while ((length = inStream.Read(bytes, 0, 4096)) > 0)
{
outStream.Write(bytes, 0, length);
&