简体   繁体   English

从客户端计算机上的文件路径加载xml文件

[英]Load xml file from file path on client machine

I basically want to do this: Allow user to enter the path of an xml file located on their local machine into a textbox.(ie. C:\\Requestxml.xml) I then want to load the xml and do stuff with it. 我基本上想这样做:允许用户将位于其本地计算机上的xml文件的路径输入到文本框中。(例如C:\\ Requestxml.xml)然后,我想加载xml并对其进行处理。

XmlDocument inputXml = new XmlDocument();
inputXml.Load(txtInputXML.Text.Trim());

This works locally, but obviously not when I deploy the site onto the server because it is looking for this path on the server. 这在本地有效,但是当我将站点部署到服务器上时显然不起作用,因为它正在服务器上寻找此路径。 I would like to know how do I get it to locate the xml file using the path on the user's local machine and not the server? 我想知道如何使用用户本地计算机而不是服务器上的路径来找到xml文件?

Solution: This is not possible. 解决方案:这是不可能的。 Decided to have user paste the xml contents into a textbox and load it that way. 决定让用户将xml内容粘贴到文本框中并以这种方式加载。

You should probably use a file input to upload the file to the server, whereby you could do whatever you like with it... 您可能应该使用文件输入将文件上传到服务器,从而可以随心所欲地对其进行处理...

<form name="MyForm"
   action="/Uploads/"
   enctype="multipart/form-data"
   method="post">
<input type="file" name="MyFile"/>
<input type="submit" value="Upload File">
</form>

If you are using Web Forms, there is an equivalent control for this that you can drag onto the page form the toolbar. 如果使用的是Web窗体,则有一个与此等效的控件,您可以将其拖动到工具栏上的页面上。

This is not possible! 这是不可能的! You have to make the user upload the file to the romote server, then open this after the upload completion. 您必须让用户将文件上传到romote服务器,然后在上传完成后将其打开。 JavaScript from browser has no access to inside user machine. 来自浏览器的JavaScript无法访问内部用户计算机。

1) Put a file upload at the page, and then make the user upload it! 1)在页面上放置文件上传,然后让用户上传!

2) Implement an event from fileupload control to read the xml and do the logic after the file upload completion. 2)从fileupload控件实现一个事件,以读取xml,并在文件上传完成后执行逻辑。

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

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