一个程序,向服务器传图片,图片名字为1,2,3,4……,要求每次上传后图片名字自动加1,
string[] dirs = Directory.GetFiles(HttpContext.Current.Server.MapPath("/") + "/picture/Statue of Liberty/");
int max=0;
//求出名字最大的图片的名字
for(int j=0;j<dirs.Length;j++)
{
if (Convert.ToInt32(dirs[j]) > max)
{
max = Convert.ToInt32(dirs[j]);
}
}
//新图片的路径
paths = HttpContext.Current.Server.MapPath("/") + "/picture/Statue of Liberty" + "/" + (max+1).ToString();
各位大侠,我哪里错了?
string[] dirs = Directory.GetFiles(HttpContext.Current.Server.MapPath("/") + "/picture/Statue of Liberty/");
int max=0;
//求出名字最大的图片的名字
for(int j=0;j<dirs.Length;j++)
{
if (Convert.ToInt32(dirs[j]) > max)
{
max = Convert.ToInt32(dirs[j]);
}
}
//新图片的路径
paths = HttpContext.Current.Server.MapPath("/") + "/picture/Statue of Liberty" + "/" + (max+1).ToString();
各位大侠,我哪里错了?
解决方案 »
- c#winform中如何拖动PictureBox控件中的图片
- 程序设计的小小小小问题请教各位高人
- c#windows窗体小问题
- 1000元求个中等难度的网页验证码识别程序,急!
- 在开发c#中怎么用键盘
- Helps the Chinese WEB programmer{支持---请回复您收集的网址或感言} 程序行动---没有分数,有的只是一颗互助的心,希望大家支持.........
- 怎么实现用c# API 自动关闭当前窗口??
- 在线等!!!请问一个关于DataGrid中的删除列的问题,谢谢!!!
- vs2008打不开曾经创建的项目
- c#打印如何调用 斑马打印机 GK888t
- 在.cs文件里不能有Response,Server等,怎么解决?
- 如何用C#做长连接得客户端?
Convert.ToInt32 转换的时候 如果dirs里的值 如果是 1.gif 这样的`
肯定会出错了
substring
lastindexof
indexof
结合使用
string[] temp = dirs[0].Split('-');则: temp[0] = "1";
temp[1] = "gif";
HttpPostedFile uplode=file.PostedFile;
//得到上传文件名
string filePath=uplode.FileName;
//得到文件后缀名
string exName=System.IO.Path.GetExtension(filePath);