A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
we tried many search in the google. but, couldn't get the exact solution for this.
You are having a hard time finding a solution because your use case is not possible. You'll need to come up with a different design approach that works with web applications.
One options is to create a web page that lists the files. Use a standard Web Forms OnClick to download the file. Keep in mind, the web application must have read rights to the file share. Below is a simple example to get you started.
namespace WebFormsDemo.FilesAndFolders
{
public partial class _default : System.Web.UI.Page
{
public const string FolderPath = @"C:\Images";
protected void Page_Load(object sender, EventArgs e)
{
FileList.DataSource = GetfilesAndFolder(FolderPath);
FileList.DataBind();
}
private string[] GetfilesAndFolder(string path)
{
return Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
}
protected void FileLinkButton_Click(object sender, EventArgs e)
{
string path = ((LinkButton)sender).Text;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", Path.GetFileName(path)));
Response.TransmitFile(path);
Response.End();
}
}
}
<asp:Repeater ID="FileList" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<ul>
<asp:LinkButton ID="FileLinkButton" runat="server" Text="<%# Container.DataItem %>" OnClick="FileLinkButton_Click" />
</ul>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>