日期:2014-05-18 浏览次数:21716 次
string  imgname = FileUpload1.PostedFile.FileName;
               string imgType = imgname.Substring(imgname.LastIndexOf(".") + 1);
               string quanname =DateTime.Now.ToString("yyyyMMddHHmmss")+imgname.LastIndexOf("\\")+"."+imgType ;
               if ("gif" != imgType && "jpg" != imgType && "GIF" != imgType && "JPG" != imgType)
                {
                    Response.Write("<script>alert('请选择gif,jpg格式的文件!');</script>");
                    return;
                }
------解决方案--------------------
openFileDialog1.InitialDirectory=("C:\\Documents and Settings\\Administrator\\桌面");
           openFileDialog1.Filter = "Excel(*.xls)|*.xls";
           DialogResult r = openFileDialog1.ShowDialog();
           string filepath = openFileDialog1.FileName;
           if (r == DialogResult.OK)
           {
               string y = openFileDialog1.FileName;
               label5.Text = y;
               button2.Visible = true;
           }
           else
           {
               label5.Text = "";
           }
------解决方案--------------------
            string test="C:\\Documents and Settings\\Lenovo User\\桌面\\code.txt";
           int i;
           String FileName;
           i=test.LastIndexOf("\\");        
           FileName=test.Substring(i + 1);    
------解决方案--------------------
Using System.IO;
string GetFileInfo(string filePath)
{
   string strEx = Path.GetExtension(filePath); //  get file extension
   string strName = Path.GetFileName(filePath); //get file name
   return (strEx+strName); // return file extension & name
}
------解决方案--------------------
Path.GetDirectoryName();