从项目目录ASPX访问外部Final

时间:2012-03-11 15:12:17

标签: asp.net vb.net

我正在尝试从项目目录中访问Web根目录的类型文件。目前它只从C:/访问它,如何让它从Web根目录访问该文件。

我希望该文件在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 个答案:

答案 0 :(得分:1)

您可以使用Server.MapPath("~/types.txt")。有关详细信息,请参阅MSDN

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