Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string strFileID = context.Request.QueryString["FileID"];
            string strSize   = context.Request.QueryString["size"];
            string tableType = context.Request.QueryString["tableType"];
            int    fileId    = 0;

            if (!int.TryParse(strFileID, out fileId))
            {
                context.Response.Write("File not found.");
                return;
            }


            string filename = "";
            string fileurl  = "";

            int tableTypeValue = 0;

            int.TryParse(tableType, out tableTypeValue);
            if (tableTypeValue == 2)
            {
                OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient();
                string str = client.GetFileInfo(fileId);
                filename = str.Substring(str.IndexOf("|") + 1);
                fileurl  = str.Substring(0, str.IndexOf("|"));
            }
            else
            {
                FilesEntity fileEntity = fileApp.Get(fileId);
                filename = fileEntity.FileTitle;
                fileurl  = fileEntity.FilePath;
            }
            if (fileurl == "")
            {
                context.Response.Write("File not found.");
                return;
            }

            string filePath = HttpContext.Current.Server.MapPath(string.Format("/{0}", fileurl));

            if (System.IO.File.Exists(filePath))
            {
                if (filename.IndexOf(".") < 0)
                {
                    filename += Path.GetExtension(filePath);
                }
                filename = filename.Replace(" ", "_");
                context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename.NoHTML()));
                context.Response.TransmitFile(filePath);
                return;
            }
            else
            {
                context.Response.Write("File not found.");
                return;
            }
        }
Пример #2
0
        protected void btnSaveFiles_Click(object sender, EventArgs e)
        {
            int id        = QS("id", 0);
            int companyid = QS("companyid", 0);

            if (fileProject.HasFile)
            {
                FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>());
                model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileProject.PostedFile);;

                model.CompanyID   = companyid;
                model.ContentType = fileProject.PostedFile.ContentType;
                model.FileID      = 0;
                model.FileSize    = fileProject.PostedFile.ContentLength;
                if (string.IsNullOrEmpty(txtFileTitle.Text))
                {
                    model.FileTitle = Path.GetFileName(fileProject.FileName);
                    model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf("."));
                }
                else
                {
                    model.FileTitle = txtFileTitle.Text;
                }
                model.IsDelete   = false;
                model.IsPublic   = UserInfo.Role == RolesEnum.CLIENT;
                model.SourceType = (int)FileSourceType.Project;
                model.ProjectId  = id;
                model.ThumbPath  = Path.GetFileName(fileProject.PostedFile.FileName);
                model.IsDelete   = false;

                FileApplication fileApp = new FileApplication();
                int             result  = fileApp.AddFile(model);

                OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient();
                List <FilesEntity> clientFiles = new List <FilesEntity>();
                clientFiles.Add(model);
                client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles));

                if (result <= 0)
                {
                    this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false);
                }
                else
                {
                    InitFiles();
                    this.ShowSuccessMessageToClient(false, false);
                    txtFileTitle.Text = "";
                }
            }
        }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = QS("id", 0);

            if (id == 0)
            {
                ShowFailMessageToClient("unauthorized access.");
                return;
            }
            else
            {
                ProjectsEntity projectEntity = new ProjectApplication().Get(id);
                if (projectEntity == null)
                {
                    ShowFailMessageToClient("unauthorized access.");
                    return;
                }

                if (fileUpload.PostedFile.ContentLength == 0)
                {
                    ShowFailMessageToClient("Please specify a file to upload.");
                    return;
                }

                FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>());
                model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileUpload.PostedFile);;

                model.CompanyID   = projectEntity.CompanyID;
                model.ContentType = fileUpload.PostedFile.ContentType;
                model.FileID      = 0;
                model.FileSize    = fileUpload.PostedFile.ContentLength;
                if (string.IsNullOrEmpty(txtFileTitle.Text))
                {
                    model.FileTitle = Path.GetFileName(fileUpload.FileName);
                    model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf("."));
                }
                else
                {
                    model.FileTitle = txtFileTitle.Text;
                }
                model.IsDelete   = false;
                model.IsPublic   = UserInfo.Role == RolesEnum.CLIENT;
                model.SourceType = (int)FileSourceType.Project;
                model.ProjectId  = id;
                model.ThumbPath  = Path.GetFileName(fileUpload.PostedFile.FileName);
                model.IsDelete   = false;

                FileApplication fileApp = new FileApplication();
                int             result  = fileApp.AddFile(model);

                OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient();
                List <FilesEntity> clientFiles = new List <FilesEntity>();
                clientFiles.Add(model);
                client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles));

                if (result <= 0)
                {
                    Redirect("File upload error.", "AddProjectFile.aspx?ID" + QS("ID"));
                }
                else
                {
                    Redirect(EmptyPopPageUrl, false, true);
                }
            }
        }