コード例 #1
0
ファイル: PdfBLL.cs プロジェクト: vijaymca/Dotnet
        /// <summary>
        /// Uploads the published document.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="bookID">The book ID.</param>
        /// <param name="docPDF">The Winnovative document PDF.</param>
        /// <param name="bookName">Name of the book.</param>
        /// <param name="listPublished">The Name of the published list.</param>
        /// <returns>Int Id</returns>
        public int UploadPublishedDocument(string context, string bookID, Document docPDF, string bookName,
                                            string listPublished)
        {
            objDAL = new CommonDAL();
            memStream = new MemoryStream();

            string strSaveToNetworkPath = PortalConfiguration.GetInstance().FindWebServiceKey("SaveToNetworkPath", context, true);
            string strNetworkPath = string.Empty;
            byte[] fileBuffer;//= new byte[1024];
            FileStream fsDWBBook = null;
            int intResult = 0;
            objCommonUtility = new CommonUtility();
            string strbookName = string.Empty;
            if (!string.Equals(listPublished, "DWB Published Library"))
            {
                string strBookGuid = Guid.NewGuid().ToString();
                strbookName = string.Format("{0}_{1}", bookName, strBookGuid);
            }
            else
            {
                strbookName = bookName;
            }
            if (!string.IsNullOrEmpty(strSaveToNetworkPath) && string.Equals(strSaveToNetworkPath.ToLowerInvariant(), YES.ToLowerInvariant()))
            {
                /// Save to the path mentioned in Portal Configuration
                strNetworkPath = PortalConfiguration.GetInstance().FindWebServiceKey("DWBNetworkPath", context, true);
                string strBookPath = string.Format(@"{0}{1}.pdf", strNetworkPath, strbookName);
                docPDF.Save(strBookPath);
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    fsDWBBook = File.Open(strBookPath, FileMode.Open, FileAccess.Read);
                });
                if (fsDWBBook != null)
                {
                    fileBuffer = new byte[fsDWBBook.Length];
                    fsDWBBook.Read(fileBuffer, 0, fileBuffer.Length);

                    if (!string.IsNullOrEmpty(strbookName))
                    {
                        intResult = objDAL.UploadPDFFileToDocumentLibrary(context, bookID, fsDWBBook, strbookName, listPublished);
                    }
                    else
                    {
                        intResult = objDAL.UploadPDFFileToDocumentLibrary(context, bookID, fsDWBBook, bookName, listPublished);
                    }
                    fsDWBBook.Close();
                }
            }
            else
            {
                ///  Save to doc library
                docPDF.Save(memStream);

                memStream.Position = 0;
                if (!string.IsNullOrEmpty(strbookName))
                {
                    intResult = objDAL.UploadPDFFileToDocumentLibrary(context, bookID, memStream, strbookName,
                                                      listPublished);
                }
                else
                {
                    intResult = objDAL.UploadPDFFileToDocumentLibrary(context, bookID, memStream, bookName,
                                                      listPublished);
                }
                memStream.Close();
            }
            return intResult;
        }