2011-03-25 58 views
0

任何人都可以給我一個解決方案,因爲我是一個新的c尖銳以下問題。文件操作

我在目錄中有很多文件。我想要加載第一個文件而不傳遞查詢字符串,第一個文件應該有下一個文件鏈接。點擊下一個鏈接按鈕後,只需傳遞查詢字符串。

如何通過從第二個文件結束文件的查詢字符串,

DirectoryInfo oImageFolderInfo = new DirectoryInfo(this.ImagePath); 
FileInfo[] oFileList = oImageFolderInfo.GetFiles("*.*"); 

string fileName=string.Empty; 

if (Request.QueryString["filename"] != null) 
{ 
    fileName=(Request.QueryString["filename"]); 

} 
else 
{ 
    fileName = oFileList[0].Name; 
} 
HtmlImage imag = new HtmlImage(); 
imag.Src = Url + fileName; 


HtmlAnchor nextAnchor = new HtmlAnchor(); 
nextAnchor.Href=?? 
nextAnchor.InnerText = "Next>>"; 

HtmlAnchor prevAnchor = new HtmlAnchor(); 
prevAnchor.Href=?? 

如何進行此相同的高達到達文件的結尾?

回答

0

您可以將文件的索引用於下一個和上一個按鈕,而不是文件名。

DirectoryInfo oImageFolderInfo = new DirectoryInfo(this.ImagePath); 
FileInfo[] oFileList = oImageFolderInfo.GetFiles("*.*"); 

string fileName=string.Empty; 
int index = 0; 
if (Request.QueryString("i") != null) 
    index = Request.QueryString("i"); 

fileName = oFileList[index].Name; 

HtmlImage imag = new HtmlImage(); 
imag.Src = Url + fileName; 

if (index > 0) 
    prevAnchor.Href = String.Format("{0}?i={1}", Url, Index - 1); 

if (index < oFileList.Count(
    nextAnchor.Href = String.Format("{0}?i={1}", Url, Index + 1);