程序问题,求助
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _5_08 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Image1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
string strName = strDir.Substring(myPos);
string strType = strName.Substring(strName.LastIndexOf(".") + 1);
string strPath = Server.MapPath(".") + strName;
if (strType == "jpg" || strType == "gif" || strType = "bmp" || strType = " png")
{
FileUpload1.SaveAs(strPath);
Image1.ImageUrl = strName;
Image1.Visible = true;
Response.Write("图片上传成功");
}
}
}
运算符“||”无法应用于“bool”和“string”类型的操作数,怎么解决?
LastIndexOf("\\")和Substring()是什么意思?
希望大家帮我一下,谢谢各位了。
上面的问题解决了又出现这样的问题:在这句string strName = strDir.Substring (myPos);出现
System.ArgumentOutOfRangeException: StartIndex 不能小于 0。 怎么办?
[[it] 本帖最后由 zore0 于 2008-9-22 13:27 编辑 [/it]]