原因:System.IO.FileNotFoundException: 未能找到文件“C:\Documents and Settings\Administrator\桌面\221.jpg”。文件名:“C:\Documents and Settings\Administrator\桌面\221.jpg” 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 在 JuSNS.Web.home.photo.addphoto.IsAllowedExtension(FileUpload hifile) 在 JuSNS.Web.home.photo.addphoto.Button1_Click(Object sender, EventArgs e)
上传部分代码
string UploadFileName, UploadFileLastName;
                                UploadFileName = FileUpload1.FileName.ToString();//文件在本地的原始位置  
                                UploadFileLastName = UploadFileName.Substring(UploadFileName.LastIndexOf(".") + 1);//得到文件的扩展名
                                Random rd = new Random();//产生随机数
                                int valationNo = 10 + rd.Next(99);//产生随机数
                                string suiji = valationNo.ToString();//产生随机数
                                string UpLoadFileTime = DateTime.Now.ToString("yyyyMMddHHmmss") + suiji;//得到系统时间并加上随机数以便生成上传图片名称
                                string NewUploadFileName = UpLoadFileTime + "." + UploadFileLastName;//产生上传图片的名称
                                string UserDirectory = SNSToKenCookie["RealName"] + SNSToKenCookie["email"];//所要创建文件夹的名字,实际运用中可为用户注册ID
                                string UserPath = HttpContext.Current.Server.MapPath("~/home/photo/uploads").ToString() + "\\" + UserDirectory;
                                if (!Directory.Exists(UserPath)) //如果文件夹不存在则创建
                                {
                                    Directory.CreateDirectory(UserPath);
                                }
                                string NewUploadPathName = UserPath + "\\" + NewUploadFileName;
                                string filepath = UserDirectory + "\\" + NewUploadFileName;
                                FileUpload1.PostedFile.SaveAs(NewUploadPathName);//用保存的方法将图片上载
                                this.tishi.Text = "上传成功";我是新手,知道的指点下,谢谢