我已經開發了在Visual Studio中的ASP.NET Web應用程序2008年文件讀寫內部asp.net web應用程序
我有一個HTML文檔和應用中的一個文本文件,但兩者都沒有在我的應用。
兩者都在外面,所以當我嘗試在另一個系統中運行相同的應用程序時,出現錯誤是因爲我缺少這些文件。
我想在應用程序中包含文件,當我部署它時。
下面是我用它來讀寫文件的代碼:
//file write test.txt
FileStream file1 = new FileStream("test.txt", FileMode.Create, FileAccess.Write);
// Create a new stream to write to the file
StreamWriter sw1 = new StreamWriter(file1);
// Write a string to the file
sw1.Write(emailId);
// Close StreamWriter
sw1.Close();
// Close file
file1.Close();
// *** Write to file ***
// Specify file, instructions, and privelegdes
FileStream file = new FileStream("test.html", FileMode.Create, FileAccess.Write);
// Create a new stream to write to the file
StreamWriter sw = new StreamWriter(file);
// Write a string to the file
sw.Write(BodyLiteral.Text);
// Close StreamWriter
sw.Close();
// Close file
file.Close();
// *** Read from file ***
// Specify file, instructions, and privelegdes
file = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Read);
// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);
// Read contents of file into a string
string cval = sr.ReadToEnd();
Response.Write(cval);
// Close StreamReader
sr.Close();
// Close file
file.Close();
//html file reading
string text = File.ReadAllText(@"D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\test.html");
我的兩個文件是:d:\ Program Files文件\微軟的Visual Studio 9.0 \ Common7 \ IDE \
我怎樣才能在應用程序中部署這兩個文件,以便該程序可以在另一個系統上工作?
請給我看看這樣的代碼 – 2009-12-17 10:46:49
如果你發現它們真的有用,你知道你可以upvote正確的答案嗎? :) – 2009-12-21 09:00:31