Could not find a part of the path

  • Thread starter Thread starter BlackBox
  • Start date Start date
B

BlackBox

If Not (oFile.PostedFile Is Nothing) Then 'Check to make sure we
actually have a file to upload

Dim strLongFilePath As String = oFile.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1,
StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath,
(Len(strLongFilePath) - intFileNameLength) + 2)

Dim uploadpath As String = Server.MapPath("~\docs\")

Select Case oFile.PostedFile.ContentType
Case "application/msword", "application/pdf" 'Make sure we
are getting a valid JPG image
oFile.PostedFile.SaveAs(uploadpath & strFileName)
txtlocation.Text = "docs\" & strFileName
lblresult.Text = strFileName & " uploaded successfully."
AddData()

Case Else
lblresult.Text = "Not a valid .doc or pdf file. Please
try again."

End Select
End If
=============================================
Getting "Could not find a part of the path". I have checked the permissions
and it is working locally but not on the Server.
Any help would be great.

Thanks
 
BlackBox said:
If Not (oFile.PostedFile Is Nothing) Then 'Check to make sure we
actually have a file to upload

Dim strLongFilePath As String = oFile.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1,
StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath,
(Len(strLongFilePath) - intFileNameLength) + 2)

Dim uploadpath As String = Server.MapPath("~\docs\")

Select Case oFile.PostedFile.ContentType
Case "application/msword", "application/pdf" 'Make sure we
are getting a valid JPG image
oFile.PostedFile.SaveAs(uploadpath & strFileName)
txtlocation.Text = "docs\" & strFileName
lblresult.Text = strFileName & " uploaded successfully."
AddData()

Case Else
lblresult.Text = "Not a valid .doc or pdf file. Please
try again."

End Select
End If
=============================================
Getting "Could not find a part of the path". I have checked the permissions
and it is working locally but not on the Server.
Any help would be great.

Thanks

My guess would be that those InStr, StrReverse, Mid functions are messing
you up. Look at the example on MSDN
(http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile(VS.80).aspx).
You should also confirm the path you are getting out at the line
oFile.PostedFile.SaveAs(uploadpath & strFileName) is actually a well formated
path to a file. You did not indicate that is the location of the error, but
it makes the most sense.

Mike
 
If Not (oFile.PostedFile Is Nothing) Then 'Check to make sure we
actually have a file to upload

Dim strLongFilePath As String = oFile.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1,
StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath,
(Len(strLongFilePath) - intFileNameLength) + 2)

Dim uploadpath As String = Server.MapPath("~\docs\")

Select Case oFile.PostedFile.ContentType
Case "application/msword", "application/pdf" 'Make sure we
are getting a valid JPG image
oFile.PostedFile.SaveAs(uploadpath & strFileName)
txtlocation.Text = "docs\" & strFileName
lblresult.Text = strFileName & " uploaded successfully."
AddData()

Case Else
lblresult.Text = "Not a valid .doc or pdf file. Please
try again."

End Select
End If
=============================================
Getting "Could not find a part of the path". I have checked the permissions
and it is working locally but not on the Server.
Any help would be great.

Thanks

Unless absolutely necessary, don't use string concatenation methods to
create file/path names, use the methods in the System.IO.Path class.
It makes it much easier:

Dim strFileName As String = Path.GetFileName(strLongFilePath)
Dim uploadpath As String = Server.MapPath("~\docs\")

....

oFile.PostedFile.SaveAs(Path.Combine(uploadpath, strFileName))


Chris
 
Back
Top