0

我正在尝试使用 Path() 但它下面有一条蓝线并说:“在声明之前不能引用局部变量(路径)。” 如何使用路径()?

Imports System.Globalization
Imports System.IO

Public Class MessageController
    Inherits System.Web.Mvc.Controller

    <EmployeeAuthorize()>
    <HttpPost()>
    Function SendReply(ByVal id As Integer, ByVal message As String, ByVal files As IEnumerable(Of HttpPostedFileBase)) As JsonResult


            ' upload files
            For Each i In files

                If (i.ContentLength > 0) Then

                    Dim fileName = path.GetFileName(i.FileName)
                    Dim path = path.Combine(Server.MapPath("~/App_Data/uploads"), fileName)
                    i.SaveAs(path)

                End If

            Next


    End Function

End Class
4

2 回答 2

2

你可以试试

Dim fileName As String
fileName = Path.GetFileName(i.FileName)
Dim path As String = Path.Combine(Server.MapPath("~/App_Data/uploads")

这里是参考

http://msdn.microsoft.com/en-us/library/system.io.path.getfilename%28v=vs.71%29.aspx

http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx

于 2012-10-17T16:58:15.490 回答
0

这里的问题是我使用Dim path的是不可能的,因为“路径”是一个保留字。

于 2012-10-23T14:31:41.780 回答