算上文件夹使用ASP.net图片 [英] Count images in Folder using ASP.net
问题描述
欲算图像的文件夹的文件夹的数量,但它会产生这样的错误:
找不到路径的一部分。C:\\内容\\幻灯片\\影像\\影像\\'
所有的图像都在该项目的文件夹。位于内容/幻灯片播放/图片/图片
这是我的code:
<%
字符串DIR = @/内容/幻灯片播放/图片/图片;
字符串[]的文件;
INT numFiles;
文件= System.IO.Directory.GetFiles(DIR);
numFiles = files.Length;
的Response.Write(图片NUM BER:+ numFiles);
%GT;
找不到路径的一部分
C:\\内容\\幻灯片\\影像\\影像\\'
块引用>表示很干脆的文件夹不存在。如果你想用户相对路径,你可以做以下。
使用Server.Mappath(〜/ {} RelativePathHere)
编辑:在回答你的评论。您将需要遍历文件,并检查每个(保持你自己数)的文件扩展名
I want to count the number of images a folder folder, but it produces this error :
Could not find a part of the path 'c:\Content\slideshow\images\image\'.
All of the images are in a folder in the project. Located a
Content/slideshow/images/image
This is my code:
<% string dir = @"/Content/slideshow/images/image"; string[] files; int numFiles; files = System.IO.Directory.GetFiles(dir); numFiles = files.Length; Response.Write("num ber of images :" + numFiles); %>
解决方案"Could not find a part of the path 'c:\Content\slideshow\images\image\'"
Means very simply that the folder does not exist. If you want to user a relative path you can do the following.
Server.MapPath("~/{RelativePathHere})
Edit : In response to your comment. You will need to loop through the file and check for file extension of each (Keeping your own count)
这篇关于算上文件夹使用ASP.net图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!