2013-11-01 3 views
-4
Private Sub CreatFolder() 
    ' the line below gives error like Conversion from string "C:\inetpub\wwwroot\Createfolders" to type 'Integer' is not valid 
    Dim directoryPath As String = Path.GetInvalidpathChars(Server.MapPath("..\Cre_Folders\File\") & txtFolderName.Text.Trim()) 

    If Not Directory.Exists(directoryPath) Then 
     Directory.CreateDirectory(directoryPath) 
     lblsuccess.Visible = True 
     'lblmsg.Visible = False 
     lblValidName.Visible = False 
     lblDelete.Visible = False 
     lblerr.Visible = False 
    Else 
     ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Folder already existed.');", True) 
     'lblmsg.Text = "Directory Already Exists..." 
     lblValidName.Visible = False 
     lblDelete.Visible = False 
     lblsuccess.Visible = False 
     lblerr.Visible = False 
    End If 

    Call Treeview() 
End Sub 
+0

Sever.MapPath를 자체 변수로 분리하고 거기에서 중단 점을 설정하고 내용을 검사합니다. – Edper

+1

가능한 복제본 [아래 코드의 경로에 잘못된 문자를 허용하려면 어떻게합니까?] (http://stackoverflow.com/questions/19699335/how-can-i-accept-illegal-characters-in-the-path- for-the-below-code) – igrimpe

+1

문제를 지정하고 질문하지 않고 코드를 제시 하시겠습니까? -1 – igrimpe

답변

1

내가 얻은 것은 컴파일 타임 오류가 아닌 런타임 오류입니다.

메서드 Path.GetInvalidPathChars()는 경로의 유효성을 검사하지 않습니다. 그것은 끈을 잡고 좋은지 나쁜지 알려줍니다. 대신 사용중인 OS에서 유효하지 않은 문자 배열을 반환합니다. MSDN Example.

반환되는 문자 목록이 완전하지 않을 수도 있습니다 (참조 : Missing ? & *).

+1

'GetInvalidPathChars'에 대한 정정을했는데 이것이 런타임 오류라고 생각합니다 : VB이고 ('추측하고 있겠지만)'Option Strict'가 꺼져있어'Server.MapPath'의 결과를 Integer '배열 인덱스, 따라서 예외. –

관련 문제