2014-04-09 71 views
0

我有一個佔位符控件,我從文件夾中添加了文件。 我還綁定了每個文件的複選框 如果點擊複選框,我如何下載文件。如何從佔位符下載文件

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告訴我,我怎樣才能通過佔位 這樣的內容,我可以findout的複選框,然後提供循環文件名來下載文件

+0

看起來似乎是,如果您有可能通過盲目接受任何用戶輸入的初始目錄路徑來暴露Web服務器上的每個文件。請小心。 –

回答

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> 

那麼這個例子是關於選擇一個下拉列表,但你可以簡單地將它重寫爲我猜的複選框。希望有助於某種方式。

+0

謝謝,但我需要在C# – Dragon