如何从占位符下载文件

本文关键字:下载 文件 占位符 | 更新日期: 2023-09-27 17:57:27

我有一个占位符控件,我在其中添加了文件夹中的文件。我还为每个文件绑定了一个复选框如果选中复选框,我如何下载文件。

string strDir = Request.QueryString["d"] == null ? FileBrowerProperty.IntialPath : Request.QueryString["d"];
//read the directory
DirectoryInfo DirInfo = new DirectoryInfo(strDir);
//read the subdirectories inside the parent directory
DirectoryInfo[] subDirs = DirInfo.GetDirectories();
//read the files in the parent directory
FileInfo[] Files = DirInfo.GetFiles();
foreach (DirectoryInfo di in subDirs)
{
    ListItem listitem1 = new ListItem(di.FullName);
    // <a href='more.php' onclick='show_more_menu()'>More >>></a>
    //add the directory info to our table 
    LiteralControl lcFolders = new LiteralControl(@"<TR><TD style='WIDTH: 20px'><input type='checkbox' id='"
       + @di.FullName
       + "'>Directory</TD><TD style='WIDTH:350px'><a href='webform1.aspx?d=" 
       + @di.FullName + "'>" + di.Name + "</a></TD><TD style='WIDTH: 150px'>" 
       + di.CreationTime + "</TD><TD style='WIDTH: 150px'>" + di.LastWriteTime 
       + "</TD></TR>");
    PlaceHolder1.Controls.Add(lcFolders);  
}

单击复选框时如何从占位符控件下载文件如果不可能,那么plz告诉我如何循环遍历占位符的内容这样我就可以找到复选框,然后提供文件名来下载文件

如何从占位符下载文件

我不是C#专家,但使用jQuery,你可以简单地做到这一点:JS:

function download(d) {
    if (d == 'Select document' && d !== '') return;
    window.location = d;
}

HTML:

 <select id="select_download" name="download" onChange="download(this.value); "> 
       <option value="">Select file</option>    
       <option id="sourcefile_download" value="http://..."> Sourcefile</option>                          
    </select>

这个例子是关于选择一个下拉列表,但我想你可以简单地为复选框重写它。希望这能有所帮助。