Reference a virtual folder

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

Is the sample below valid for referencing a virtual folder named OracleFiles
in a web site where the aspx page that is using this code is under the root
folder of the subweb? Some users are getting exception errors. Thanks.

Dim strPath As String = Server.MapPath("~/OracleFiles")

-David
 
Sorry. Error is below.

An unhandled exception occurred:

Message: The network path was not found.



Stack Trace:

at System.IO.__Error.WinIOError(Int32 errorCode, String

maybeFullPath)

at System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption)

at System.IO.Directory.GetFiles(String path, String searchPattern,
SearchOption searchOption)

at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory

FileOrDirectory, String directory, String wildCard)

at

Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDir

ectory FileOrDirectory, String directory, SearchOption searchType, String[]
wildcards, Collection`1 Results)

at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String

directory, SearchOption searchType, String[] wildcards)

at UtilClass.FilesInPathType(String strPhyPath, String strSuffix) in
http://server//FileRoom/App_Code/UtilClass.vb:line 94

at ASP.frmmain_aspx.__Render__control1(HtmlTextWriter __w, Control

parameterContainer) in http://server//fileroom/frmMain.aspx:line 39

at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter

writer, ICollection children)

at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)

at System.Web.UI.Page.Render(HtmlTextWriter writer)

at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)

at System.Web.UI.Page.ProcessRequestMain(Boolean

includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
Here is the lines of code that are part of the problem. The user tells me
that the error is intermittant and apparently is only happening to 1 user.
The process is in the Page_Load event where I am checking to see if any .txt
files exist in a virtual folder to give a warning that there are unprocessed
files that need attention.

If Page.IsPostBack = False Then
'1st time in page so check for Oracle import files
Dim strPath As String = Server.MapPath("~/OracleFiles")
'Use shared function in UtilClass to return count of txt files
Dim intFiles As Int32 = UtilClass.FilesInPathType(strPath,
"*.txt")
If intFiles > 0 Then
If intFiles = 1 Then
txtMsg.Text = "There is 1 Oracle check request import
file to be processed."
Else
txtMsg.Text = "There are " & intFiles.ToString & "
Oracle check request import files to be processed."
End If
End If
End If

I wonder if it would be a problem if someone deleted any .txt files a split
second before this process was checked by another user? Thanks.

David

Patrice said:
From the stack it doesn't appear to be in this function. I would say
rather that you do a recursive search and that it could fail if the user
is not allowed to browse all directories or if some other users remove a
directory when another one is doing something.

If it always fails for a given user, it would be a clue...

Plus in case you can just make sure (we just stuff this value in a session
variable and this is shown our next error report allwing us to check if
needed if the value is correct).

To add to Mark and not sure what is his intent, but it doesns't seems to
be a bug in Server.MapPath but rather that it was misued by the user. You
correctly used ~/ so it will return the path for OracleFiles under your
application root (and not under the site root whihc could cause a
problem).

Moreover this is the kind of server side code that is not user dependent.
So the problem IMHO is definitely not with Server.MapPath...

--
Patrice

David C said:
Sorry. Error is below.

An unhandled exception occurred:

Message: The network path was not found.



Stack Trace:

at System.IO.__Error.WinIOError(Int32 errorCode, String

maybeFullPath)

at System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption)

at System.IO.Directory.GetFiles(String path, String searchPattern,
SearchOption searchOption)

at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory

FileOrDirectory, String directory, String wildCard)

at

Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDir

ectory FileOrDirectory, String directory, SearchOption searchType,
String[] wildcards, Collection`1 Results)

at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String

directory, SearchOption searchType, String[] wildcards)

at UtilClass.FilesInPathType(String strPhyPath, String strSuffix) in
http://server//FileRoom/App_Code/UtilClass.vb:line 94

at ASP.frmmain_aspx.__Render__control1(HtmlTextWriter __w, Control

parameterContainer) in http://server//fileroom/frmMain.aspx:line 39

at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter

writer, ICollection children)

at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)

at System.Web.UI.Page.Render(HtmlTextWriter writer)

at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)

at System.Web.UI.Page.ProcessRequestMain(Boolean

includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Mark Rae said:
Some users are getting exception errors.

When posting to a technical newsgroup because users are getting errors,
it's really important to actually say what the errors are...
 
The line setting intFiles variable that calls the following function in a
class

Public Shared Function FilesInPathType(ByVal strPhyPath As String, _
ByVal strSuffix As String) As Integer
Dim intFiles As Integer =
My.Computer.FileSystem.GetFiles(strPhyPath,
FileIO.SearchOption.SearchTopLevelOnly, strSuffix).Count
FilesInPathType = intFiles
End Function
 
Back
Top