如何从占位符下载文件

时间:2014-04-09 07:07:30

标签: c# asp.net placeholder

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

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告诉我如何循环占位符的内容 这样我就可以找到复选框,然后提供文件名来下载文件

1 个答案:

答案 0 :(得分:0)

我不是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>

这个例子是关于选择一个下拉菜单,但你可以简单地重写一下我猜的复选框。希望有所帮助。