PC Review


Reply
Thread Tools Rate Thread

Could not find a part of the path

 
 
BlackBox
Guest
Posts: n/a
 
      10th Aug 2009
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


 
Reply With Quote
 
 
 
 
Family Tree Mike
Guest
Posts: n/a
 
      11th Aug 2009


"BlackBox" wrote:

> 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/libr...8VS.80%29.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
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      17th Aug 2009
On Aug 10, 4:30 pm, "BlackBox" <replymeo...@hotmail.com> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not find a part of the path =?Utf-8?B?TGFycnkgRXBu?= Microsoft Dot NET Framework 7 21st Feb 2007 06:16 PM
Could not find a part of the path gogaz@rediffmail.com Microsoft ASP .NET 3 31st Aug 2006 04:14 PM
Could not find a part of the path Matías Microsoft Dot NET Framework 5 15th Mar 2006 06:37 PM
Could not find a part of the path =?Utf-8?B?REpL?= Microsoft Dot NET 0 21st Sep 2005 12:51 AM
Could Not Find Part of a Path Tom Microsoft C# .NET 1 15th Jan 2004 02:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:57 AM.