2012-03-11 31 views
0

我想从Web根目录的项目目录中访问类型文件。目前它只能从C:\访问它,我怎么能从Web根目录下访问这个文件。从项目目录访问外部最终ASPX

我想将文件作为types.txt放在项目文件夹中。

Dim fs As StreamReader 
    Dim rdr As FileStream = New FileStream("/types.txt", FileMode.Open, FileAccess.Read) 
    fs = New StreamReader(rdr) 
    While Not fs.EndOfStream 
     Dim line As String = fs.ReadLine() 'reads each line in file 
     Dim line2 As String = fs.ReadLine() 'reads each line in file 
     Dim final As String = line + " types at " + line2 + "%" 
     mortBox.Items.Add(final) 'adds each lines to combo box 

     'adds values to array list, this will allow the list to grow with new entries to the file 
     arrayT.Add(line) 
     arrayR.Add(line2) 

    End While 

    rdr.Close() 'closes open file 

回答

1

您可以使用Server.MapPath("~/types.txt")。详情请参阅MSDN

代字号字符“〜”将替换为Web应用程序根目录的路径。