Esempio n. 1
0
        protected void btnB_Click(object sender, EventArgs e)
        {
            _cookieHelper.GetCookieValue("FileId", out _fileId);
            if (string.IsNullOrEmpty(_fileId))
            {
                //_fileId = ConfigurationManager.AppSettings["FileId"];
                _fileId = txtId.Text.Trim();
            }

            if (string.IsNullOrEmpty(_fileId))
            {
                AlertMsg("fileidempty", "请填写文件id!");
            }

            GridFSBriefInfo info     = _h.GetFileInfo(_fileId);
            var             fileName = info.FileName;
            string          path     = Path.Combine(_fileSavePath, fileName);

            if (!File.Exists(path))
            {
                AlertMsg("edit", "文件需要签出才能进行编辑!");
            }
            else
            {
                string url = GetEditorUrl(fileName);
                if (string.IsNullOrEmpty(url))
                {
                    AlertMsg("filetypeerror", "文件类型不支持编辑!");
                }
                else
                {
                    Response.Redirect(string.Format(url, fileName));
                }
            }
        }
Esempio n. 2
0
        protected void btnS_Click(object sender, EventArgs e)
        {
            _cookieHelper.GetCookieValue("FileId", out _fileId);
            if (string.IsNullOrEmpty(_fileId))
            {
                //_fileId = ConfigurationManager.AppSettings["FileId"];
                _fileId = txtId.Text.Trim();
            }

            if (string.IsNullOrEmpty(_fileId))
            {
                AlertMsg("fileidempty", "请填写文件id!");
            }

            GridFSBriefInfo info     = _h.GetFileInfo(_fileId);
            var             filename = info.FileName;

            if (FileToGridfs(filename))
            {
                AlertMsg("checkin", "签入成功!");
            }
            else
            {
                AlertMsg("nofile", "没有可签入的文件!");
            }
        }
Esempio n. 3
0
        public bool FileToGridfs(string fileName)
        {
            string path = Path.Combine(_fileSavePath, fileName);

            if (!File.Exists(path))
            {
                return(false);
            }
            // 把 byte[] 写入文件
            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                GridFSBriefInfo info = _h.AddFile(fs, fileName);
                _cookieHelper.CreateCookie("FileId", info.FileId);
            }

            File.Delete(path);
            return(true);
        }
Esempio n. 4
0
        protected void btnE_Click(object sender, EventArgs e)
        {
            _cookieHelper.GetCookieValue("FileId", out _fileId);
            if (string.IsNullOrEmpty(_fileId))
            {
                //_fileId = ConfigurationManager.AppSettings["FileId"];
                _fileId = txtId.Text.Trim();
            }

            if (string.IsNullOrEmpty(_fileId))
            {
                AlertMsg("fileidempty", "请填写文件id!");
            }

            GridFSBriefInfo info = _h.GetFileInfo(_fileId);

            StringBuilder sb = new StringBuilder();

            sb.Append("文件Id:" + info.FileId + "<br/>");
            sb.Append("文件名:" + info.FileName + "<br/>");
            sb.Append("文件大小:" + info.Length + "<br/>");
            sb.Append("文件MD5:" + info.Md5 + "<br/>");
            sb.Append("<hr/>");

            litList.Text = sb.ToString();

            var    filename     = info.FileName;
            Stream gridfsStream = _h.GetFile(_fileId);
            bool   isExist      = StreamToFile(gridfsStream, filename);

            if (!isExist)
            {
                AlertMsg("fileischeckout", "文件已被签出,签入后才能再次签出");
            }
            else
            {
                AlertMsg("checkout", "签出成功");
            }
        }