【问题标题】:C# MVC Get full file pathC# MVC 获取完整文件路径
【发布时间】:2016-03-31 03:13:42
【问题描述】:


首先,我要声明我为此挖了一半的互联网,而且我发现的所有地方:“不,你不能这是网络浏览器的安全性”。
我需要这个用于 ASP 中的 Intranet 网页。 NET MVC5 + C#。 应该允许用户在某种对话框中选择文件或文件夹。 Then when selected I would like to get back the path of slected item [also files or folders on network drives.但不是像 z:\... 这样的映射路径,我更喜欢 \\Server50\folder\folder2\file.ext]
然后我想将此路径发送到 SQL DB 以执行某些操作。 (这很容易)

这就是我想要完整的 UNC 路径的原因。没有要上传的文件。

谁能给我一些线索,从哪里寻找或开始?

【问题讨论】:

  • 正如您已经在一半的互联网上发现的那样,出于安全原因,您试图实现的目标是不可能的。您可以通过在客户端计算机上安装专有的 ActiveX 组件来实现这一点。
  • 我不相信“不可能”的情况。如果有这么多人问这个问题,那么必须有一个解决方案。然后我将搜索 ActiveX 解决方案。
  • 不要使用 ActiveX。这是一项死技术。 lifehacker.com.au/2015/05/…

标签: javascript c# model-view-controller activex


【解决方案1】:

因此现在可以用于 Intranet 目的;]
我在客户端使用了 MVC+Silverlight+证书

将 Silverlight 项目添加到 Visual Studio 解决方案:
right-click 在 MVC 应用项目上->Properties
SilverLight Application tab-> Add...:
-检查Copy to configuration specific folder
-取消选中Add a test page...
-检查enable Silverlight debugging

银光:在 .xaml.cs 主页:

 public MainPage()
    {
        InitializeComponent();
        LayoutRoot.Drop += new DragEventHandler(drop);//important to add
    }

    private void drop(object sender, DragEventArgs e)
    {
        if (e.Data!=null)
        {
            FileInfo[] files = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
            foreach(var item in files)
             {
                 //fullpath in: item.Fullname property
              }
        }
    }


在 xaml 主页设计中

 <Grid x:Name="LayoutRoot" Background="#FFBF6666" AllowDrop="true">
    <Button x:Name="button" Content="Button" HorizontalAlignment="Left"     Margin="72,38,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
 </Grid>


right-click Silverlight Project->Properties
Signing tab-> 勾选Sign the xap file->Create the test certificate


在 MVC 应用中查看设置:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div id="silverlightControlHost">
 <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="1000" height="800">
    <param name="source" value="/ClientBin/System.xap" />
    <param name="onError" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="5.0.61118.0" />
    <param name="autoUpgrade" value="true" />
    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
      <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none" />
    </a>
 </object>
  </div>
</asp:Content>


重建两个项目
部署到生产服务器
...trusted root authorities 的客户端安装创建的证书

现在可以正常使用了;]

我看到有些人在 web.config 中添加了 .xap、.xaml 扩展名,但对我来说没有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 2018-10-24
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多