我正在阅读一个文本文件,其中包含在我正在处理的 MVC 网站中使用 C# 的 SQL 插入语句。调试我正在使用的函数时工作正常并且插入发生。但是,一旦我发布该网站并在本地计算机上运行它(甚至将 IIS 设置为使用 asp.net 4.0),它似乎就不起作用了。
if (Request.Files != null && Request.Files["txtImportFile"] != null)
{
//newFilePath = Server.MapPath("\\" + DateTime.Now.Ticks + Request.Files["txtImportFile"].FileName);
string[] temp_string = Request.Files["txtImportFile"].FileName.Split(new char[] { '\\' });
string temp_filename = temp_string[temp_string.Count() - 1];
//newFilePath = Server.MapPath("\\temp\\" + DateTime.Now.Ticks + Request.Files["txtImportFile"].FileName);
newFilePath = Server.MapPath("\\temp\\" + DateTime.Now.Ticks + temp_filename);
Request.Files["txtImportFile"].SaveAs(newFilePath);
StreamReader reader = new StreamReader(newFilePath);
string contents = reader.ReadToEnd();
reader.Close();
Models.WingsRemoteDbLibrary dbLib = new Models.WingsRemoteDbLibrary();
string update_message = dbLib.UpdateSlaveItemsTable(contents);
if (System.IO.File.Exists(newFilePath))
System.IO.File.Delete(newFilePath);
RandomPopupView(update_message);
}
我希望我的解释听起来并不含糊。我会尽力回答任何进一步的问题。谢谢。
解决方法:
而不是使用
Server.MapPath("\\temp\\"...
在根目录下创建名为“temp”的文件夹并使用
System.Web.HttpContext.Current.Request.MapPath("~\\temp....
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)