private Guid OpenDocumentID(string documentID)
        {
            var unitOfWork = new DocumentsUnitOfWork();

            var documentItem     = unitOfWork.ItemRepository.GetByID(long.Parse(documentID));
            var documentItemInfo = new DocumentItemInfo(documentItem);

            var editorType = documentItemInfo.DocumentProcessorType;
            OfficeWorkSessionControl editor = null;

            if (editorType == OfficeDocumentProcessorType.Spreadsheet)
            {
                var spreadsheetControl = new ASPxSpreadsheet();
                spreadsheetControl.Open(
                    documentItemInfo.Id,
                    (DevExpress.Spreadsheet.DocumentFormat)DocumentFormatUtils.GetDocumentFormat(documentItemInfo.NameExtension),
                    () => documentItem.Content.Data);

                editor = spreadsheetControl;
            }

            if (editorType == OfficeDocumentProcessorType.RichEdit)
            {
                var richEditControl = new ASPxRichEdit();
                richEditControl.Open(
                    documentItemInfo.Id,
                    (DevExpress.XtraRichEdit.DocumentFormat)DocumentFormatUtils.GetDocumentFormat(documentItemInfo.NameExtension),
                    () => documentItem.Content.Data);

                editor = richEditControl;
            }

            return(editor.GetWorkSessionID());
        }
    protected void re_Init(object sender, EventArgs e)
    {
        ASPxRichEdit richEdit = sender as ASPxRichEdit;
        GridViewEditItemTemplateContainer container = richEdit.NamingContainer as GridViewEditItemTemplateContainer;

        string documentID = GetDocumentID(container.Grid);

        if (!OpenedCanceledDocumentIDs.Contains(documentID))
        {
            OpenedCanceledDocumentIDs.Add(documentID);
        }

        if (container.Grid.IsNewRowEditing)
        {
            richEdit.DocumentId = documentID;
            return;
        }

        //for text in db
        string rtfText = container.Grid.GetRowValues(container.VisibleIndex, "RtfContent").ToString();

        //for binary in db
        //byte[] rtfBinary = (byte[])container.Grid.GetRowValues(container.VisibleIndex, "RtfContent");

        richEdit.Open(documentID, DocumentFormat.Rtf, () => {
            //for text in db
            return(Encoding.UTF8.GetBytes(rtfText));

            //for binary in db
            //return rtfBinary;
        });
    }
Exemplo n.º 3
0
    private void OpenWordFile(string fileFullPath)
    {
        ASPxRichEdit richEdit = new ASPxRichEdit();

        richEdit.ID = "richEdit";
        ASPxPopupControl1.Controls.Add(richEdit);
        richEdit.Open(fileFullPath);
    }
Exemplo n.º 4
0
        protected void pageControlDetails_Load(object sender, EventArgs e)
        {
            if (Session["fileNameToDownload"] != null)
            {
                string fileURL         = Session["fileNameToDownload"].ToString().Split('|')[0];
                string FileExtn        = Session["fileNameToDownload"].ToString().Split('|')[1];
                string fileName        = Session["fileNameToDownload"].ToString().Split('|')[2];
                string storageFileName = Session["fileNameToDownload"].ToString().Split('|')[3];

                ASPxPageControl pageControlDetails = (ASPxPageControl)sender;

                //HtmlGenericControl documentDownloadLink = (HtmlGenericControl)pageControlDetails.FindControl("previewNotAvailableText");
                //documentDownloadLink.Visible = true;
                //documentDownloadLink.InnerHtml = "<a href=\"" + fileURL + "\" download=\"" + fileName + "\">Download File</a>";

                if (FileExtn == ".txt")
                {
                    ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview");
                    richEditPreview.Visible = true;
                    //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL);
                    richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.PlainText, () =>
                    {
                        byte[] fileData = null;
                        using (var wc = new System.Net.WebClient())
                            fileData = wc.DownloadData(fileURL);
                        return(new MemoryStream(fileData));
                    });
                }
                else if (FileExtn == ".doc")
                {
                    ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview");
                    richEditPreview.Visible = true;
                    //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL);
                    richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.Doc, () =>
                    {
                        byte[] fileData = null;
                        using (var wc = new System.Net.WebClient())
                            fileData = wc.DownloadData(fileURL);
                        return(new MemoryStream(fileData));
                    });
                }
                else if (FileExtn == ".docx")
                {
                    ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview");
                    richEditPreview.Visible = true;
                    //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL);
                    richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.OpenXml, () =>
                    {
                        byte[] fileData = null;
                        using (var wc = new System.Net.WebClient())
                            fileData = wc.DownloadData(fileURL);
                        return(new MemoryStream(fileData));
                    });
                }
                else if (FileExtn == ".xls")
                {
                    DevExpress.Web.ASPxSpreadsheet.ASPxSpreadsheet spreadSheetPreview = (ASPxSpreadsheet)pageControlDetails.FindControl("spreadSheetPreview");
                    spreadSheetPreview.Visible = true;
                    MemoryStream stream = new MemoryStream();
                    spreadSheetPreview.Open(Guid.NewGuid().ToString(), DevExpress.Spreadsheet.DocumentFormat.Xls, () =>
                    {
                        byte[] fileData = null;
                        using (var wc = new System.Net.WebClient())
                            fileData = wc.DownloadData(fileURL);
                        return(new MemoryStream(fileData));
                    });

                    //spreadSheetPreview.
                }
                else if (FileExtn == ".xlsx")
                {
                    DevExpress.Web.ASPxSpreadsheet.ASPxSpreadsheet spreadSheetPreview = (ASPxSpreadsheet)pageControlDetails.FindControl("spreadSheetPreview");
                    spreadSheetPreview.Visible = true;
                    MemoryStream stream = new MemoryStream();
                    spreadSheetPreview.Open(Guid.NewGuid().ToString(), DevExpress.Spreadsheet.DocumentFormat.Xlsx, () =>
                    {
                        byte[] fileData = null;
                        using (var wc = new System.Net.WebClient())
                            fileData = wc.DownloadData(fileURL);
                        return(new MemoryStream(fileData));
                    });

                    //spreadSheetPreview.
                }
                else if (FileExtn == ".pdf")
                {
                    HtmlGenericControl pdfPreview = (HtmlGenericControl)pageControlDetails.FindControl("pdfPreview");
                    pdfPreview.Visible = true;
                    using (var client = new System.Net.WebClient())
                    {
                        client.DownloadFile(fileURL, Server.MapPath("~/TempFiles") + "/" + fileName);
                    }

                    //pdfPreview.InnerHtml = "<embed src = \""+ Path.GetTempPath() + "\\" + fileURL+"\" />";
                    pdfPreview.InnerHtml = "<iframe src=\"" + "../TempFiles" + "/" + fileName + "\" style = \"width:100%; height:500px;\" frameborder = \"0\" ></iframe> ";
                    //pdfPreview.InnerHtml = "<iframe src = \"" + fileURL + "\" style = \"width:600px; height:500px;\" frameborder = \"0\"></iframe>";
                }
                else if (FileExtn == ".jpg" || FileExtn == ".jpeg")
                {
                    HtmlGenericControl imgPreview = (HtmlGenericControl)pageControlDetails.FindControl("pdfPreview");
                    imgPreview.Visible   = true;
                    imgPreview.InnerHtml = "<img class=\"preview\" src = \"" + fileURL + "\">";
                }
                else
                {
                    HtmlGenericControl previewNotAvailableText = (HtmlGenericControl)pageControlDetails.FindControl("documentDownloadLink");
                    previewNotAvailableText.Visible   = true;
                    previewNotAvailableText.InnerHtml = "<h1>Preview Not Available</h1>";
                }
            }
        }