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