我有一個文件,用戶瀏覽並點擊上傳按鈕,我將文件保存在服務器上,appdata/uploads在應用程序目錄中。然後我嘗試使用流讀取器讀取它,然後解析它。在我的本地開發環境中,它工作正常,但是當我將其部署在服務器上時,它根本不起作用。有什麼建議麼??謝謝mvc3 c#streamreader文件沒有讀取
//Save LoadList File:
DateTime uploadDate = DateTime.Now;
string destinationPath = string.Format("{0}\\{1}\\{2}\\{3}\\", Server.MapPath("~/App_Data/uploads"), uploadDate.ToString("yyyy"), uploadDate.ToString("MMM"), uploadDate.ToString("dd"));
if (!Directory.Exists(destinationPath))
Directory.CreateDirectory(destinationPath);
string storedFileName = string.Format("{0}{1}.json", destinationPath, System.Guid.NewGuid());
file.ElementAt(0).SaveAs(storedFileName);
//FileImport is a static class
var Pair = FileImport.CyclesCompleted(storedFileName);
private static string LoadTextFromFile(string fileName)
{
StreamReader streamReader = new StreamReader(fileName);
string text = streamReader.ReadToEnd();
streamReader.Close();
return text;
}
我假設該文件被放置在IIS用戶有權訪問的文件夾中?沒有看到太多,這可能是一個安全問題。 –
是否有例外? –
以及即時改變我的方法現在,即時通訊讀取文件保存之前,但做這樣的事情[鏈接] http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.inputstream.aspx 。我只想看看如何將字符串發送到流媒體閱讀器。因爲在我的代碼的其他部分,我使用streamreader來解析我的文件內容。謝謝 – user1475788