日期:2014-05-18 浏览次数:20515 次
 #region 重新上传新资源
        private void FN_UpdateFile()
        {
            fileid = Request["fielid"];//获取文件编号
            folderid = Request["folderid"];//获取文件夹编号
            NRBLL.File bf = new Asiastar.NRBLL.File();
            Guid guid = new Guid(fileid);
            string createby = bf.FN_GetResListByFileid(guid).Tables[0].Rows[0]["CreateBy"].ToString();
            string createon = bf.FN_GetResListByFileid(guid).Tables[0].Rows[0]["CreateOn"].ToString();
            string modefyon = bf.FN_GetResListByFileid(guid).Tables[0].Rows[0]["ModefyOn"].ToString();
            string modefyBy = bf.FN_GetResListByFileid(guid).Tables[0].Rows[0]["ModefyBy"].ToString();
            if (bf.FN_GetResListByFileid(guid) != null || bf.FN_GetResListByFileid(guid).Tables[0].Rows.Count > 0)
            {
                string path = bf.FN_GetResListByFileid(guid).Tables[0].Rows[0]["FilePath"].ToString();//数据库中的文件完整路径
                if (path != null)   //如果这个文件存在
                {
                    System.IO.File.Delete(path);//先在服务器中删除
                }
                //遍历上传表单元素     开始重新上传
                HttpFileCollection files = HttpContext.Current.Request.Files;
                try
                {
                    for (int iFile = 0; iFile < files.Count; iFile++)
                    {
                        //检查文件扩展名字
                        HttpPostedFile postedFile = files[iFile];
                        string fileName = "";//定义文件名
                        //string fileExtension = "";
                        fileName = Path.GetFileName(postedFile.FileName);//得到上传文件的完整名称 即文件名+后缀名
                        int index = fileName.IndexOf(".");
                        string FileType = fileName.Substring(index).ToLower();//截取文件后缀名
                        Guid fileGuid = Guid.NewGuid();//生成新的文件名称 以GUID命名防止文件名相同
                        string NewFileName = fileGuid.ToString();//新的文件名
                        NewFileName = NewFileName + FileType;//新的文件名+后缀名
                        if (fileName != "")
                        {
                            try
                            {
                                string strpath = System.Web.HttpContext.Current.Server.MapPath("~/Upload/") + NewFileName;
                                NRModel.File model = new Asiastar.NRModel.File();
                                NRBLL.File nbf = new Asiastar.NRBLL.File();
                                Guid guid1 = new Guid(fileid);
                                Guid guid2 = new Guid(folderid);
                                Guid guid3 = new Guid(createby);
                                Guid guid4 = new Guid(modefyBy);
                                model.Fileid = guid1;
                                model.Folderid = guid2;
                                model.Filepath = strpath;
                                model.FileNam = fileName;
                                model.FileSize = postedFile.ContentLength;
                                model.Decription =