下面一段程序中这两条语句的作用是什么??string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
FileUpload1.Visible = true;
string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
string strFileName = strDir.Substring(myPos);
string strPath = Server.MapPath(".") + strFileName;
this.Label2.Text = "保存路径:";
this.Label2.Text += strPath;
FileUpload1.PostedFile.SaveAs(strPath);
this.Label5.Visible = true;
this.Label1.Text = "文件名称:";
this.Label1.Text += FileUpload1.PostedFile.FileName;
this.Label3.Text = "文件类型:";
this.Label3.Text += FileUpload1.PostedFile.ContentType;
this.Label4.Text = "文件大小:";
this.Label4.Text += FileUpload1.PostedFile.ContentLength.ToString();
}
int myPos = strDir.LastIndexOf("\\");
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
FileUpload1.Visible = true;
string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
string strFileName = strDir.Substring(myPos);
string strPath = Server.MapPath(".") + strFileName;
this.Label2.Text = "保存路径:";
this.Label2.Text += strPath;
FileUpload1.PostedFile.SaveAs(strPath);
this.Label5.Visible = true;
this.Label1.Text = "文件名称:";
this.Label1.Text += FileUpload1.PostedFile.FileName;
this.Label3.Text = "文件类型:";
this.Label3.Text += FileUpload1.PostedFile.ContentType;
this.Label4.Text = "文件大小:";
this.Label4.Text += FileUpload1.PostedFile.ContentLength.ToString();
}
string strDir = FileUpload1.PostedFile.FileName; //获取上传的文件名
int myPos = strDir.LastIndexOf("\\");//获取文件名中"\"字符所在的位置
2.得到文件名最后一个"/"
因为上传的文件名是类似"c:/.../.../fdfd.jsp";
这样得到最后一个"/"后就可以通过subString方式得到文件名"fdfd.jsp"