Reference a virtual folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David C

    #1

    Reference a virtual folder

    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


  • Mark Rae [MVP]

    #2
    Re: Reference a virtual folder

    "David C" <dlchase@lifeti meinc.comwrote in message
    news:OQs3WfsPJH A.3596@TK2MSFTN GP06.phx.gbl...
    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...


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • David C

      #3
      Re: Reference a virtual folder

      Sorry. Error is below.

      An unhandled exception occurred:

      Message: The network path was not found.



      Stack Trace:

      at System.IO.__Err or.WinIOError(I nt32 errorCode, String

      maybeFullPath)

      at System.IO.Direc tory.InternalGe tFileDirectoryN ames(String path, String
      userPathOrigina l, String searchPattern, Boolean includeFiles, Boolean
      includeDirs, SearchOption searchOption)

      at System.IO.Direc tory.GetFiles(S tring path, String searchPattern,
      SearchOption searchOption)

      at Microsoft.Visua lBasic.FileIO.F ileSystem.FindP aths(FileOrDire ctory

      FileOrDirectory , String directory, String wildCard)

      at

      Microsoft.Visua lBasic.FileIO.F ileSystem.FindF ilesOrDirectori es(FileOrDir

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

      at Microsoft.Visua lBasic.MyServic es.FileSystemPr oxy.GetFiles(St ring

      directory, SearchOption searchType, String[] wildcards)

      at UtilClass.Files InPathType(Stri ng strPhyPath, String strSuffix) in
      http://server//FileRoom/App_Code/UtilClass.vb:line 94

      at ASP.frmmain_asp x.__Render__con trol1(HtmlTextW riter __w, Control

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

      at System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter

      writer, ICollection children)

      at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)

      at System.Web.UI.P age.Render(Html TextWriter writer)

      at System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
      ControlAdapter adapter)

      at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer, ControlAdapter
      adapter)

      at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)

      at System.Web.UI.P age.ProcessRequ estMain(Boolean

      includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)

      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:uc$1DmsPJH A.4760@TK2MSFTN GP02.phx.gbl...
      "David C" <dlchase@lifeti meinc.comwrote in message
      news:OQs3WfsPJH A.3596@TK2MSFTN GP06.phx.gbl...
      >
      >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...
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Mark Rae [MVP]

        #4
        Re: Reference a virtual folder

        "David C" <dlchase@lifeti meinc.comwrote in message
        news:%23ASYj1sP JHA.1516@TK2MSF TNGP03.phx.gbl. ..
        >>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
        >>
        >What is the error?
        >
        Sorry. Error is below.
        >
        An unhandled exception occurred:
        >
        Message: The network path was not found.
        >
        Stack Trace:
        >
        at System.IO.__Err or.WinIOError(I nt32 errorCode, String maybeFullPath)
        Server.MapPath doesn't always return what you think it should:


        If you set a breakpoint on the line in question and inspect
        Server.MapPath( "~/OracleFiles"), what does it show? Is it correct?

        What does Request.ServerV ariables("APPL_ PHYSICAL_PATH ") return? Is that
        correct?


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Patrice

          #5
          Re: Reference a virtual folder

          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" <dlchase@lifeti meinc.coma écrit dans le message de groupe de
          discussion : #ASYj1sPJHA.151 6@TK2MSFTNGP03. phx.gbl...
          Sorry. Error is below.
          >
          An unhandled exception occurred:
          >
          Message: The network path was not found.
          >
          >
          >
          Stack Trace:
          >
          at System.IO.__Err or.WinIOError(I nt32 errorCode, String
          >
          maybeFullPath)
          >
          at System.IO.Direc tory.InternalGe tFileDirectoryN ames(String path, String
          userPathOrigina l, String searchPattern, Boolean includeFiles, Boolean
          includeDirs, SearchOption searchOption)
          >
          at System.IO.Direc tory.GetFiles(S tring path, String searchPattern,
          SearchOption searchOption)
          >
          at Microsoft.Visua lBasic.FileIO.F ileSystem.FindP aths(FileOrDire ctory
          >
          FileOrDirectory , String directory, String wildCard)
          >
          at
          >
          Microsoft.Visua lBasic.FileIO.F ileSystem.FindF ilesOrDirectori es(FileOrDir
          >
          ectory FileOrDirectory , String directory, SearchOption searchType,
          String[] wildcards, Collection`1 Results)
          >
          at Microsoft.Visua lBasic.MyServic es.FileSystemPr oxy.GetFiles(St ring
          >
          directory, SearchOption searchType, String[] wildcards)
          >
          at UtilClass.Files InPathType(Stri ng strPhyPath, String strSuffix) in
          http://server//FileRoom/App_Code/UtilClass.vb:line 94
          >
          at ASP.frmmain_asp x.__Render__con trol1(HtmlTextW riter __w, Control
          >
          parameterContai ner) in http://server//fileroom/frmMain.aspx:line 39
          >
          at System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter
          >
          writer, ICollection children)
          >
          at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
          >
          at System.Web.UI.P age.Render(Html TextWriter writer)
          >
          at System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
          ControlAdapter adapter)
          >
          at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
          ControlAdapter adapter)
          >
          at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
          >
          at System.Web.UI.P age.ProcessRequ estMain(Boolean
          >
          includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
          >
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:uc$1DmsPJH A.4760@TK2MSFTN GP02.phx.gbl...
          >"David C" <dlchase@lifeti meinc.comwrote in message
          >news:OQs3WfsPJ HA.3596@TK2MSFT NGP06.phx.gbl.. .
          >>
          >>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...
          >>
          >>
          >--
          >Mark Rae
          >ASP.NET MVP
          >http://www.markrae.net
          >
          >

          Comment

          • David C

            #6
            Re: Reference a virtual folder

            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.Files InPathType(strP ath,
            "*.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.ToStri ng & "
            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" <http://www.chez.com/scribe/wrote in message
            news:645F5D92-B531-47BF-952F-D550085843A0@mi crosoft.com...
            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" <dlchase@lifeti meinc.coma écrit dans le message de groupe de
            discussion : #ASYj1sPJHA.151 6@TK2MSFTNGP03. phx.gbl...
            >Sorry. Error is below.
            >>
            >An unhandled exception occurred:
            >>
            >Message: The network path was not found.
            >>
            >>
            >>
            >Stack Trace:
            >>
            >at System.IO.__Err or.WinIOError(I nt32 errorCode, String
            >>
            >maybeFullPat h)
            >>
            >at System.IO.Direc tory.InternalGe tFileDirectoryN ames(String path, String
            >userPathOrigin al, String searchPattern, Boolean includeFiles, Boolean
            >includeDirs, SearchOption searchOption)
            >>
            >at System.IO.Direc tory.GetFiles(S tring path, String searchPattern,
            >SearchOption searchOption)
            >>
            >at Microsoft.Visua lBasic.FileIO.F ileSystem.FindP aths(FileOrDire ctory
            >>
            >FileOrDirector y, String directory, String wildCard)
            >>
            >at
            >>
            >Microsoft.Visu alBasic.FileIO. FileSystem.Find FilesOrDirector ies(FileOrDir
            >>
            >ectory FileOrDirectory , String directory, SearchOption searchType,
            >String[] wildcards, Collection`1 Results)
            >>
            >at Microsoft.Visua lBasic.MyServic es.FileSystemPr oxy.GetFiles(St ring
            >>
            >directory, SearchOption searchType, String[] wildcards)
            >>
            >at UtilClass.Files InPathType(Stri ng strPhyPath, String strSuffix) in
            >http://server//FileRoom/App_Code/UtilClass.vb:line 94
            >>
            >at ASP.frmmain_asp x.__Render__con trol1(HtmlTextW riter __w, Control
            >>
            >parameterConta iner) in http://server//fileroom/frmMain.aspx:line 39
            >>
            >at System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter
            >>
            >writer, ICollection children)
            >>
            >at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
            >>
            >at System.Web.UI.P age.Render(Html TextWriter writer)
            >>
            >at System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
            >ControlAdapt er adapter)
            >>
            >at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
            >ControlAdapt er adapter)
            >>
            >at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
            >>
            >at System.Web.UI.P age.ProcessRequ estMain(Boolean
            >>
            >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
            >>
            >"Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
            >news:uc$1DmsPJ HA.4760@TK2MSFT NGP02.phx.gbl.. .
            >>"David C" <dlchase@lifeti meinc.comwrote in message
            >>news:OQs3WfsP JHA.3596@TK2MSF TNGP06.phx.gbl. ..
            >>>
            >>>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...
            >>>
            >>>
            >>--
            >>Mark Rae
            >>ASP.NET MVP
            >>http://www.markrae.net
            >>
            >>
            >

            Comment

            • Mark Rae [MVP]

              #7
              Re: Reference a virtual folder

              "David C" <dlchase@lifeti meinc.comwrote in message
              news:OzBs8Q1PJH A.1164@TK2MSFTN GP03.phx.gbl...
              Here is the lines of code that are part of the problem.
              A couple of questions:

              1) Do you know which specific line throws the exception?

              2) Do you have exception handling around this code?


              --
              Mark Rae
              ASP.NET MVP


              Comment

              • Patrice

                #8
                Re: Reference a virtual folder

                From the stack this is inside UtilClass.Files InPathType(strP ath, "*.txt")...
                likely in a GetFiles method...

                --
                Patrice

                "David C" <dlchase@lifeti meinc.coma écrit dans le message de groupe de
                discussion : OzBs8Q1PJHA.116 4@TK2MSFTNGP03. phx.gbl...
                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.Files InPathType(strP ath,
                "*.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.ToStri ng & "
                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" <http://www.chez.com/scribe/wrote in message
                news:645F5D92-B531-47BF-952F-D550085843A0@mi crosoft.com...
                >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" <dlchase@lifeti meinc.coma écrit dans le message de groupe de
                >discussion : #ASYj1sPJHA.151 6@TK2MSFTNGP03. phx.gbl...
                >>Sorry. Error is below.
                >>>
                >>An unhandled exception occurred:
                >>>
                >>Message: The network path was not found.
                >>>
                >>>
                >>>
                >>Stack Trace:
                >>>
                >>at System.IO.__Err or.WinIOError(I nt32 errorCode, String
                >>>
                >>maybeFullPath )
                >>>
                >>at System.IO.Direc tory.InternalGe tFileDirectoryN ames(String path, String
                >>userPathOrigi nal, String searchPattern, Boolean includeFiles, Boolean
                >>includeDirs , SearchOption searchOption)
                >>>
                >>at System.IO.Direc tory.GetFiles(S tring path, String searchPattern,
                >>SearchOptio n searchOption)
                >>>
                >>at Microsoft.Visua lBasic.FileIO.F ileSystem.FindP aths(FileOrDire ctory
                >>>
                >>FileOrDirecto ry, String directory, String wildCard)
                >>>
                >>at
                >>>
                >>Microsoft.Vis ualBasic.FileIO .FileSystem.Fin dFilesOrDirecto ries(FileOrDir
                >>>
                >>ectory FileOrDirectory , String directory, SearchOption searchType,
                >>String[] wildcards, Collection`1 Results)
                >>>
                >>at Microsoft.Visua lBasic.MyServic es.FileSystemPr oxy.GetFiles(St ring
                >>>
                >>directory, SearchOption searchType, String[] wildcards)
                >>>
                >>at UtilClass.Files InPathType(Stri ng strPhyPath, String strSuffix) in
                >>http://server//FileRoom/App_Code/UtilClass.vb:line 94
                >>>
                >>at ASP.frmmain_asp x.__Render__con trol1(HtmlTextW riter __w, Control
                >>>
                >>parameterCont ainer) in http://server//fileroom/frmMain.aspx:line 39
                >>>
                >>at System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter
                >>>
                >>writer, ICollection children)
                >>>
                >>at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
                >>>
                >>at System.Web.UI.P age.Render(Html TextWriter writer)
                >>>
                >>at System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
                >>ControlAdapte r adapter)
                >>>
                >>at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
                >>ControlAdapte r adapter)
                >>>
                >>at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
                >>>
                >>at System.Web.UI.P age.ProcessRequ estMain(Boolean
                >>>
                >>includeStages BeforeAsyncPoin t, Boolean includeStagesAf terAsyncPoint)
                >>>
                >>"Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                >>news:uc$1DmsP JHA.4760@TK2MSF TNGP02.phx.gbl. ..
                >>>"David C" <dlchase@lifeti meinc.comwrote in message
                >>>news:OQs3Wfs PJHA.3596@TK2MS FTNGP06.phx.gbl ...
                >>>>
                >>>>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...
                >>>>
                >>>>
                >>>--
                >>>Mark Rae
                >>>ASP.NET MVP
                >>>http://www.markrae.net
                >>>
                >>>
                >>
                >
                >

                Comment

                • David C

                  #9
                  Re: Reference a virtual folder

                  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.Fil eSystem.GetFile s(strPhyPath,
                  FileIO.SearchOp tion.SearchTopL evelOnly, strSuffix).Coun t
                  FilesInPathType = intFiles
                  End Function

                  "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                  news:uubBH71PJH A.5044@TK2MSFTN GP03.phx.gbl...
                  "David C" <dlchase@lifeti meinc.comwrote in message
                  news:OzBs8Q1PJH A.1164@TK2MSFTN GP03.phx.gbl...
                  >
                  >Here is the lines of code that are part of the problem.
                  >
                  A couple of questions:
                  >
                  1) Do you know which specific line throws the exception?
                  >
                  2) Do you have exception handling around this code?
                  >
                  >
                  --
                  Mark Rae
                  ASP.NET MVP
                  http://www.markrae.net

                  Comment

                  Working...