简体   繁体   English

从客户端计算机读取XML文件-获取-拒绝访问路径

[英]Reading XML file from Client machine - getting - Access to the path is denied

I'm currently trying to READ XML file from the client machine where the user can open from any location (there is no specific location). 我目前正在尝试从客户端计算机上读取XML文件,用户可以从任何位置打开该文件(没有特定位置)。 However, i browse to the folder and select the xml file and when it execute this line (below) it throw an error complaining about access to the path is denied any idea how should i approach? 但是,我浏览到该文件夹​​并选择xml文件,当它执行此行时(下面),它会抛出一个错误,抱怨对路径的访问被拒绝了,我不知道该怎么办?

error: System.UnauthorizedAccessException: Access to the path is Denied 错误: System.UnauthorizedAccessException:对路径的访问被拒绝

Dim reader As New XmlTextReader(System.IO.Path.GetFullPath(File1.PostedFile.FileName)) 

            Dim m_xmlr As XmlTextReader
            'Create the XML Reader
            m_xmlr = New XmlTextReader(System.IO.Path.GetFullPath(File1.PostedFile.FileName.ToString()))
            'Disable whitespace so that you don't have to read over whitespaces
            m_xmlr.WhitespaceHandling = WhitespaceHandling.None
            'read the xml declaration and advance to family tag
            m_xmlr.Read()   **<<<<<ERROR**
            'read the family tag
            m_xmlr.Read()
            'Load the Loop
            While Not m_xmlr.EOF
                 ..............
                 .............

Your code is running on the server. 您的代码正在服务器上运行。 You can't just read from the client's local drive like that. 您不能像这样从客户端的本地驱动器读取数据。 You should use the InputStream of the file to get the data. 您应该使用文件的InputStream来获取数据。 For example: 例如:

Dim m_xmlr As XmlReader = XmlReader.Create(File1.PostedFile.InputStream)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM