2011-03-25 62 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);