[英]C# MVC Get full file path
首先,我要指出的是,我為此花了一半的時間在Internet上進行了挖掘:“不,您不能保證Web瀏覽器的安全性”。
對於ASP中的Intranet網頁,我需要此功能。 NET MVC5 + C#。 應該允許用戶在某種對話框中選擇文件或文件夾。 然后,選擇該選項后,我想返回選定項目的路徑[也包括網絡驅動器上的文件或文件夾。 但是,我不喜歡像\\ z:\\ ...這樣的映射路徑,而是\\\\ Server50 \\ folder \\ folder2 \\ file.ext]
然后,我想將此路徑發送到SQL DB進行某些操作。 (這很容易)
這就是我想要完整的UNC路徑的原因。 沒有要上傳的文件。
誰能給我一些線索,從哪里尋找或開始?
因此,現在有可能用於Intranet;]
我在客戶端使用了MVC + Silverlight +證書
將Silverlight項目添加到Visual Studio解決方案:
right-click
MVC應用程序的Project-> Properties
SilverLight Application tab
-> Add...
:
-選中“ Copy to configuration specific folder
-取消選中Add a test page...
-check 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
選項卡->選中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擴展名,但對我而言卻無濟於事。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.