C# MVC Get full file path

北城以北 提交于 2019-12-13 00:49:01

问题



First of all I will state that I digged half of the Internet for this and everywhere I find:"No You cannot it is web browser security".
I need this for Intranet webpage in ASP. NET MVC5 + C#. User should be allowed to select file or folder in some kind of dialog. Then when selected I would like to get back the path of slected item [also files or folders on network drives. But instead of mapped path like z:\... I prefer \\Server50\folder\folder2\file.ext]
Then I want to send this path to SQL DB for some actions. (that's easy part)

That's the reason I want full UNC path. No files to be uploaded.

Can anyone give me some kind of clue where to look for or start?


回答1:


So it is possible now for intranet purposes;]
I used MVC+Silverlight+certificate on client side

Adding Silverlight Project to Visual Studio Solution:
right-click on MVC app Project->Properties
SilverLight Application tab-> Add...:
-check Copy to configuration specific folder
-uncheck Add a test page...
-check enable Silverlight debugging

Silver light:in .xaml.cs main page:

 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
              }
        }
    }


in xaml main page design

 <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-> check Sign the xap file->Create the test certificate


View setup in MVC app:

<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>


Rebuild both projects
Deploy to production server
Install created certificate on client side in ...trusted root authorities

Now it is working;]

I saw some people adding .xap, .xaml extension to web.config but for me it did not help.



来源:https://stackoverflow.com/questions/34456787/c-sharp-mvc-get-full-file-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!