Beispiel #1
0
    private void Process_AddLibraryItem()
    {
        PermissionData security_data;
        //Dim folder_data As FolderData
        LibraryConfigData lib_setting_data;
        Collection pagedata;
        string strOperation = "";
        string strLibType = "";
        string strContentId = "";
        long CurrentUserID = 0;
        Ektron.Cms.Library.EkLibrary m_refLibrary;
        string FileName = "";
        string NewFilename = "";
        string MediaPath = "";
        string Extensions = "";
           string[] FilenameArray;
        bool ret = false;
        bool uploadok = false;
          string[] ExtensionArray; //, gtLibraries
           int iLoop;
        bool bThumbnail = true;
        object szPhysicalPath; // ,ThumbLBString
           string actErrorString;

        CurrentUserID = _ContentApi.UserId;
        m_refLibrary = _ContentApi.EkLibraryRef;

        Ektron.Cms.DataIO.EkLibraryRW dataLibObj;
        dataLibObj = new Ektron.Cms.DataIO.EkContentRW(_ContentApi.RequestInformationRef);
        Collection cItemInfo = new Collection();

        try
        {
            if ((_Type == "images") || (_Type == "files"))
            {

                int fileLength = frm_filename.PostedFile.ContentLength;
                byte[] fileData = new byte[fileLength];
                frm_filename.PostedFile.InputStream.Read(fileData, 0, fileLength);
                Stream stream = new MemoryStream(fileData);
                if (EkFunctions.IsImage(Path.GetExtension(frm_filename.PostedFile.FileName)))
                {
                    if (!EkFunctions.isImageStreamValid(stream))
                    {
                        throw new Exception("The image is corrupted or not in correct format.");
                    }
                }

                _FolderId = Convert.ToInt64(Request.Form["frm_folder_id"]);
                strLibType = Request.Form["frm_libtype"];
                strOperation = Request.Form["frm_operation"];
                FileName = (string)(frm_filename.PostedFile.FileName.Substring((frm_filename.PostedFile.FileName).LastIndexOf("\\") + 1));
                FileName = FileName.Replace("%", "");
                lib_setting_data = _ContentApi.GetLibrarySettings(_FolderId);
                security_data = _ContentApi.LoadPermissions(_FolderId, "folder", 0);
                strContentId = Request.Form["frm_content_id"];
                pagedata = new Collection();
                pagedata.Add(_FolderId, "ParentID", null, null);
                pagedata.Add(Request.Form["frm_library_id"], "LibraryID", null, null);
                pagedata.Add(strLibType, "LibraryType", null, null);
                pagedata.Add(Request.Form["frm_title"], "LibraryTitle", null, null);
                pagedata.Add(strContentId, "ContentID", null, null);
                NewFilename = Strings.Trim(Request.Form["frm_oldfilename"]);

                if (((strOperation.ToLower() != "overwrite") && (((security_data.CanAddToImageLib) && (strLibType == "images")) || ((security_data.CanAddToFileLib) && (strLibType == "files")) || ((security_data.CanAddToHyperlinkLib) && (strLibType == "hyperlinks")) || ((security_data.CanAddToQuicklinkLib) && (strLibType == "quicklinks")))) || ((security_data.CanOverwriteLib) && (strOperation.ToLower() == "overwrite")))
                {
                    pagedata.Add(CurrentUserID, "UserID", null, null);
                    FilenameArray = FileName.Split('.');
                    if (strLibType == "images")
                    {
                        Extensions = lib_setting_data.ImageExtensions;
                        MediaPath = lib_setting_data.ImageDirectory;
                    }
                    else
                    {
                        Extensions = lib_setting_data.FileExtensions;
                        MediaPath = lib_setting_data.FileDirectory;
                    }
                    if ((FilenameArray.Length - 1) >= 1)
                    {
                        ExtensionArray = Extensions.Split(',');
                        for (iLoop = 0; iLoop <= (ExtensionArray.Length - 1); iLoop++)
                        {
                            if (Strings.LCase(FilenameArray[FilenameArray.Length - 1]).Trim() == Strings.LCase((string)(ExtensionArray[iLoop])).Trim())
                            {
                                uploadok = true;
                                break;
                            }
                        }
                        if (uploadok == true)
                        {
                            if (strOperation.ToLower() == "overwrite")
                            {
                                pagedata.Add("OverwriteLib", "UpdateLibData", null, null);
                                strOperation = "overwrite";
                            }
                            else
                            {
                                strOperation = "makeunique";
                            }

                            szPhysicalPath = Server.MapPath(MediaPath);
                            if (!Directory.Exists(szPhysicalPath.ToString()))
                            {
                                Directory.CreateDirectory(szPhysicalPath.ToString());
                            }

                            if (strOperation == "overwrite")
                            {
                                actErrorString = NewFilename;
                            }
                            else
                            {
                                actErrorString = FileName;
                            }

                            string strTmpFilename;
                            string strTmpFileExtn;
                            int iUnqueNameIdentifier =0 ;
                            FileInfo CheckFile;
                            actErrorString = Strings.Replace(actErrorString.ToString(), "/", "\\", 1, -1, 0);
                            string[] st = Strings.Split(actErrorString.ToString(), "\\", -1, 0);
                            strTmpFilename = st[st.Length-1];
                            if ((Strings.Right(szPhysicalPath.ToString(), 1) != "\\"))
                            {
                                szPhysicalPath = szPhysicalPath + "\\";
                            }

                            actErrorString = strTmpFilename;
                            strTmpFileExtn = actErrorString.Substring(actErrorString.LastIndexOf("."));
                            strTmpFilename = Strings.Replace(actErrorString.ToString(), strTmpFileExtn.ToString(), "", 1, -1, 0);
                            if (strOperation == "makeunique")
                            {
                                CheckFile = new FileInfo(szPhysicalPath + actErrorString);
                                if (CheckFile.Exists)
                                {
                                    while (CheckFile.Exists)
                                    {
                                        iUnqueNameIdentifier = iUnqueNameIdentifier + 1;
                                        actErrorString = strTmpFilename + "(" + iUnqueNameIdentifier + ")" + strTmpFileExtn;
                                        CheckFile = new FileInfo(szPhysicalPath + actErrorString);
                                    }
                                }
                            }

                            if (!Directory.Exists(szPhysicalPath.ToString()))
                            {
                                Directory.CreateDirectory(szPhysicalPath.ToString());
                            }

                            try
                            {
                                if ((strOperation.ToLower() != "overwrite") && (strLibType == "images" || strLibType == "files"))
                                {
                                    cItemInfo = dataLibObj.GetChildLibraryItemByTitlev2_0(Convert.ToString( Request.Form["frm_title"]), _FolderId, strLibType,Convert.ToInt32( EkEnumeration.CMSContentType.LibraryItem));
                                    if ((cItemInfo.Count > 0) && (Convert.ToInt32( cItemInfo["ContentLanguage"]) == _ContentApi.RequestInformationRef.ContentLanguage))
                                    {
                                        Utilities.ShowError(_MessageHelper.GetMessage("com: library entry already exists"));
                                        return;
                                    }
                                }
                            }
                            catch (Exception)
                            {

                            }

                            frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString);

                            if (strLibType == "images")
                            {
                                try
                                {
                                    Utilities.ProcessThumbnail(Server.MapPath(MediaPath), actErrorString.ToString());
                                }
                                catch (Exception)
                                {
                                    bThumbnail = false;
                                }
                            }
                            else
                            {
                                bThumbnail = false;
                            }
                            //----------------- Load Balance ------------------------------------------------------
                            LoadBalanceData[] loadbalance_data;
                            int i = 0;
                            loadbalance_data = _ContentApi.GetAllLoadBalancePathsExtn(_FolderId, strLibType);
                            if (!(loadbalance_data == null))
                            {
                                for (i = 0; i <= loadbalance_data.Length - 1; i++)
                                {
                                    szPhysicalPath = Server.MapPath(loadbalance_data[i].Path);
                                    if ((Strings.Right(szPhysicalPath.ToString(), 1) != "\\"))
                                    {
                                        szPhysicalPath = szPhysicalPath + "\\";
                                    }
                                    frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString);
                                    if (bThumbnail)
                                    {
                                        Utilities.ProcessThumbnail(szPhysicalPath.ToString(), actErrorString.ToString());
                                    }

                                }
                            }
                            pagedata.Add(MediaPath + actErrorString, "LibraryFilename", null, null);
                        }
                        else
                        {
                            throw (new Exception(_MessageHelper.GetMessage("error: invalid extension")));
                        }
                    }
                    else
                    {
                        throw (new Exception(_MessageHelper.GetMessage("error: invalid extension")));
                    }
                }
                else
                {
                    throw (new Exception(_MessageHelper.GetMessage("com: user does not have permission")));
                }
            }
            else
            {
                pagedata = new Collection();
                pagedata.Add(Request.Form["frm_folder_id"], "ParentID", null, null);
                pagedata.Add(Request.Form["frm_libtype"], "LibraryType", null, null);
                pagedata.Add(Request.Form["frm_title"], "LibraryTitle", null, null);
                pagedata.Add(Request.Form["frm_filename"], "LibraryFilename", null, null);
                pagedata.Add(Request.Form["frm_content_id"], "ContentID", null, null);
                pagedata.Add(_ContentLanguage, "ContentLanguage", null, null);
                pagedata.Add(CurrentUserID, "UserID", null, null);
            }
            if (_Type != "quicklinks" && _Type != "forms")
            {
                pagedata.Add(GetFormTeaserData(), "ContentTeaser", null, null);
                pagedata.Add(CollectMetaField(), "ContentMetadata", null, null);
            }

            //Adding the Taxonomy category info
            if ((Request.Form["TaxonomyOverrideId"] != null) && Convert.ToInt64(Request.Form["TaxonomyOverrideId"]) != 0)
            {
                TaxonomyOverrideId = Convert.ToInt64( Request.Form["TaxonomyOverrideId"]);
                TaxonomyTreeIdList = Convert.ToString( TaxonomyOverrideId);
            }

            if ((Request.Form[taxonomyselectedtree.UniqueID] != null) && Request.Form[taxonomyselectedtree.UniqueID] != "")
            {
                TaxonomyTreeIdList = Request.Form[taxonomyselectedtree.UniqueID];
                if (TaxonomyTreeIdList.Trim().EndsWith(","))
                {
                    TaxonomyTreeIdList = TaxonomyTreeIdList.Substring(0, TaxonomyTreeIdList.Length - 1);
                }
            }
            if (TaxonomyTreeIdList.Trim() == string.Empty && TaxonomySelectId > 0)
            {
                TaxonomyTreeIdList = Convert.ToString( TaxonomySelectId);
            }
            pagedata.Add(TaxonomyTreeIdList, "Taxonomy", null, null);
            ///'

            if (strOperation == "overwrite")
            {
                ret = m_refLibrary.UpdateLibraryItemByIDv2_0(pagedata, 0, -1);
                FolderData folder_data = _ContentApi.GetFolderById(_FolderId);
                if (folder_data.FolderType == Convert.ToInt32( EkEnumeration.FolderType.Catalog))
                {
                    LibraryData library_data = null;
                    library_data = _ContentApi.GetLibraryItemByID(_Id, _FolderId);
                    FileName = library_data.FileName.Substring(System.Convert.ToInt32((library_data.FileName).LastIndexOf("/") + 1));
                    Ektron.Cms.Commerce.ProductTypeData productTypeData = new Ektron.Cms.Commerce.ProductTypeData();
                    Ektron.Cms.Commerce.ProductType productType = new Ektron.Cms.Commerce.ProductType(_ContentApi.RequestInformationRef);
                    long xmlConfigurationId = folder_data.XmlConfiguration[0].Id;

                    productTypeData = productType.GetItem(xmlConfigurationId);
                    szPhysicalPath = Server.MapPath(MediaPath);

                    if (productTypeData.DefaultThumbnails.Count > 0)
                    {
                        EkFileIO thumbnailCreator = new EkFileIO();
                        bool thumbnailResult = false;
                        string sourceFile = (string)(szPhysicalPath + FileName);
                        foreach (ThumbnailDefaultData thumbnail in productTypeData.DefaultThumbnails)
                        {
                            string fileNameNoExtension = FileName.Replace(System.IO.Path.GetExtension(FileName), "");
                            string fileNameExtension = System.IO.Path.GetExtension(FileName);
                            string thumbnailFile = (string)(szPhysicalPath + "\\" + fileNameNoExtension + thumbnail.Title + fileNameExtension);
                            thumbnailResult = thumbnailCreator.CreateThumbnail(sourceFile, thumbnailFile, thumbnail.Width, thumbnail.Height);
                        }
                    }
                    LibraryData librarydata = new LibraryData();
                    int iThumbnail = 0;
                    if (productTypeData.DefaultThumbnails.Count > 0)
                    {
                        string sourceFile = (string)(szPhysicalPath + FileName);
                        foreach (ThumbnailDefaultData thumbnail in productTypeData.DefaultThumbnails)
                        {
                            iThumbnail++;
                            string fileNameNoExtension = FileName.Replace(System.IO.Path.GetExtension(FileName), "");
                            string fileNameExtension = System.IO.Path.GetExtension(FileName);
                            string thumbnailPath = library_data.FileName.Replace(System.IO.Path.GetFileName(library_data.FileName), "");
                            string thumbnailFile = fileNameNoExtension + thumbnail.Title + fileNameExtension;
                            NewFilename = Strings.Trim(Request.Form["frm_oldfilename"]);

                            librarydata =  new LibraryData();
                            librarydata.Type = "images";
                            librarydata.FileName = thumbnailPath + thumbnailFile;
                            librarydata.Title = library_data.Title + thumbnail.Title;
                            librarydata.ParentId = _FolderId;
                            librarydata.Id = _Id + iThumbnail;
                            actErrorString = NewFilename;

                            Collection ThumbnailData = new Collection();
                            ThumbnailData.Add(librarydata.ParentId, "ParentID", null, null);
                            ThumbnailData.Add(librarydata.Id, "LibraryID", null, null);
                            ThumbnailData.Add(librarydata.Type, "LibraryType", null, null);
                            ThumbnailData.Add(librarydata.Title, "LibraryTitle", null, null);
                            ThumbnailData.Add(strContentId, "ContentID", null, null);
                            ThumbnailData.Add(CurrentUserID, "UserID", null, null);
                            ThumbnailData.Add("OverwriteLib", "UpdateLibData", null, null);
                            ThumbnailData.Add(librarydata.FileName, "LibraryFilename", null, null);
                            ThumbnailData.Add(librarydata.OriginalLibraryId, "OriginalLibraryId", null, null);

                            _ContentApi.UpdateLibraryItemByID(ThumbnailData);
                        }
                    }

                }
            }
            else
            {
                if (_ContentLanguage == Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES)
                {
                    _ContentApi.ContentLanguage = _ContentApi.DefaultContentLanguage;
                }
                ret = m_refLibrary.AddLibraryItemv2_0(pagedata, 0);

                // process tag info
                ProcessTags(Convert.ToInt64( pagedata["LibraryID"]), _ContentApi.ContentLanguage);
            }

            if (strOperation.ToLower() == "overwrite")
            {
                Response.Redirect("library.aspx?LangType=" + _ContentLanguage + "&action=ViewLibraryItem&id=" + pagedata["LibraryID"] + "&parent_id=" + pagedata["ParentID"] + "&reload=true", false);
            }
            else
            {
                Response.Redirect((string)("library.aspx?LangType=" + _ContentLanguage + "&action=ViewLibraryByCategory&id=" + _FolderId + "&type=" + strLibType), false);
            }
        }
        catch (Exception ex)
        {
            EkException.ThrowException(ex);
        }
    }
Beispiel #2
0
    private void Process_Form()
    {
        string filename = "";
            object BinaryFormData;
            Collection cLibrary = new Collection();
            string lib_filename = "";
            bool UploadOk = false;
            int iLoop = 0;
            string szPhysicalPath = "";
            LoadBalanceData[] extrPaths;
            string libt2 = "";
            string tmpfolder;
            string tmptype;
            Array filenamearray;
            string extensions;
            string MediaPath = "";
            Array ExtensionArray;
            string actErrorString;
            string ErrDescription;

            Ektron.Cms.DataIO.EkLibraryRW dataLibObj;
            dataLibObj = new Ektron.Cms.DataIO.EkContentRW(m_refContentApi.RequestInformationRef);
            Collection cItemInfo = new Collection();

            if (action == "overwritelibraryitem")
            {
                operation = "overwrite";
            }
            else
            {
                operation = "makeunique";
            }

            try
            {
                Information.Err().Clear();
                BinaryFormData = Request.BinaryRead(Request.TotalBytes);
            }
            catch
            {
                if (Information.Err().Number != 0)
                {
                    if (-2147467259 == Information.Err().Number)
                    {
                        ErrDescription = "Error: The file being upload is larger than what is allowed in the IIS. ";
                        ErrDescription = ErrDescription + "Please change the ASPMaxRequestEntityAllowed to a larger number in the metabase.xml file (usually located in c:\\windows\\system32\\inetsrv). ";
                        Response.Write(ErrDescription + '\r' + '\n' + "<br/>");
                    }
                    Response.Write(Information.Err().Description);
                }
                return;
            }

            cLibrary.Add(m_folder, "ParentID", null, null);
            m_LibType = Request.Form["frm_libtype"];
            cLibrary.Add(m_LibType, "LibraryType", null, null);
            cLibrary.Add(Request.Form["frm_title"], "LibraryTitle", null, null);
            filename = (string) (frm_filename.PostedFile.FileName.Substring((frm_filename.PostedFile.FileName).LastIndexOf("\\") + 1));

            int fileLength = frm_filename.PostedFile.ContentLength;
            byte[] fileData = new byte[fileLength];
            frm_filename.PostedFile.InputStream.Read(fileData, 0, fileLength);
            Stream stream = new MemoryStream(fileData);
            if (EkFunctions.IsImage(Path.GetExtension(frm_filename.PostedFile.FileName)))
            {
                if (!EkFunctions.isImageStreamValid(stream))
                {
                    throw new Exception("The image is corrupted or not in correct format.");
                }
            }

            cLibrary.Add(Request.Form["frm_content_id"], "ContentID", null, null);
            if (operation == "overwrite")
            {
                cLibrary.Add(Request.Form["frm_library_id"], "LibraryID", null, null);
                if (Request.Form["hidden_filename"].IndexOf("?") != -1)
                {
                    lib_filename = (string) (Request.Form["hidden_filename"].Substring(0, System.Convert.ToInt32(Request.Form["hidden_filename"].IndexOf("?"))));
                }
                else
                {
                    lib_filename = Request.Form["hidden_filename"];
                }

            }

            if (((operation.ToLower() != "overwrite") &&
                (((m_cPerms.CanAddToImageLib) && (cLibrary["LibraryType"].ToString() == "images"))
                || ((m_cPerms.CanAddToFileLib) && (cLibrary["LibraryType"].ToString() == "files"))
                || ((m_cPerms.CanAddToHyperlinkLib) && (cLibrary["LibraryType"].ToString() == "hyperlinks"))
                || ((m_cPerms.CanAddToQuicklinkLib) && (cLibrary["LibraryType"].ToString() == "quicklinks"))))
                || ((m_cPerms.CanOverwriteLib) && (operation.ToLower() == "overwrite")))
                {
                cLibrary.Add(currentUserID, "UserID", null, null);

                tmpfolder = cLibrary["ParentID"].ToString();
                tmptype = cLibrary["LibraryType"].ToString();
                filenamearray = filename.Split('.');
                if (tmptype == "images")
                {
                    extensions = lib_setting_data.ImageExtensions;
                }
                else
                {
                    extensions = lib_setting_data.FileExtensions;
                }

                if ((filenamearray.Length - 1) >= 1)
                {
                    ExtensionArray = extensions.Split(',');

                    for (iLoop = 0; iLoop <= (ExtensionArray.Length - 1); iLoop++)
                    {
                        if (filenamearray.GetValue(filenamearray.Length-1).ToString().ToLower().Trim() == ExtensionArray.GetValue(iLoop).ToString().ToLower().Trim())
                        {
                            UploadOk = true;
                            break;
                        }
                    }
                    if (UploadOk == true)
                    {
                        if (tmptype == "images")
                        {
                            MediaPath = lib_setting_data.ImageDirectory;
                        }
                        else if (tmptype == "files")
                        {
                            MediaPath = lib_setting_data.FileDirectory;
                        }
                        szPhysicalPath = getPhysicalPath(MediaPath);
                        if (! Directory.Exists(szPhysicalPath))
                        {
                            Directory.CreateDirectory(szPhysicalPath);
                        }

                        actErrorString = filename;
                        if (lib_filename.Trim().Length > 0)
                        {
                            actErrorString = lib_filename;
                        }
                        string[] strTmpFilename;
                        int iUnqueNameIdentifier = 0;
                        FileInfo CheckFile;
                        actErrorString = actErrorString.Replace("/", "\\");
                        strTmpFilename = actErrorString.Split('\\');
                        if ((szPhysicalPath.Substring(szPhysicalPath.Length - 1, 1) != "\\"))
                        {
                            szPhysicalPath = szPhysicalPath + "\\";
                        }
                        string strFileName = "";
                        string strFileExtn = "";
                        actErrorString = (string)(strTmpFilename.GetValue(strTmpFilename.Length - 1));
                        strFileExtn = actErrorString.Substring(actErrorString.LastIndexOf("."));
                        strFileName = actErrorString.Replace(strFileExtn, "");
                        if (operation == "makeunique")
                        {
                            CheckFile = new FileInfo(szPhysicalPath + actErrorString);
                            if (CheckFile.Exists)
                            {
                                while (CheckFile.Exists)
                                {
                                    iUnqueNameIdentifier++;
                                    actErrorString = (string)(strFileName + "(" + iUnqueNameIdentifier + ")" + strFileExtn);
                                    CheckFile = new FileInfo(szPhysicalPath + actErrorString);
                                }
                            }
                        }

                        try
                        {
                            if (operation.ToLower() != "overwrite" && cLibrary["LibraryType"].ToString()  == "images")
                            {
                                cItemInfo = dataLibObj.GetChildLibraryItemByTitlev2_0(Request.Form["frm_title"].ToString(),m_folder,cLibrary["LibraryType"].ToString(),Convert.ToInt32(Ektron.Cms.Common.EkEnumeration.CMSContentType.LibraryItem));
                                if ((cItemInfo.Count > 0) && (Convert.ToInt32(cItemInfo["ContentLanguage"]) == m_refContentApi.RequestInformationRef.ContentLanguage))
                                {
                                    Utilities.ShowError(m_refMsg.GetMessage("com: library entry already exists"));
                                    return;
                                }
                            }
                        }
                        catch (Exception)
                        {

                        }

                        try
                        {
                            frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString);
                        }
                        catch (Exception ex)
                        {
                            Response.Write("<html><head><link rel=\"STYLESHEET\" href=\"csslib/ektron.workarea.css\" type=\"text/css\"></head><body>");
                            Response.Write("<table><tr><td class=\"titlebar-error\">" + ex.Message + "<td></tr></table></body></html>");
                            Response.End();
                        }
                        if (tmptype == "images")
                        {
                            // Thumbnails only run if it is an image.
                            string thumbnailPath;
                            thumbnailPath = getPhysicalPath(MediaPath);
                            Utilities.ProcessThumbnail(thumbnailPath, actErrorString);
                        }
                        //----------------- Load Balance ------------------------------------------------------
                        if (tmptype == "images")
                        {
                            libt2 = "images";
                        }
                        else
                        {
                            libt2 = "files";
                        }

                        extrPaths = m_refContentApi.GetAllLoadBalancePathsExtn(m_folder, libt2);
                        if (!(extrPaths == null))
                        {
                            for (iLoop = 0; iLoop <= extrPaths.Length - 1; iLoop++) //Each lbObj In extrPaths
                            {
                                //actErrorString will contain the name of the file that was loaded on the main directory
                                szPhysicalPath = getPhysicalPath(extrPaths[iLoop].Path);
                                if ((szPhysicalPath.Substring(szPhysicalPath.Length - 1, 1) != "\\"))
                                {
                                    szPhysicalPath = szPhysicalPath + "\\";
                                }
                                try
                                {
                                    frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString);
                                    Utilities.ProcessThumbnail(szPhysicalPath, actErrorString);
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        extrPaths = null;

                        //----------------------- /Load Balance --------------------------------------------------------

                        cLibrary.Add(MediaPath + actErrorString, "LibraryFilename", null, null);

                    }
                }
            }
            else
            {
                EkException.ThrowException(new System.Exception(m_refMsg.GetMessage("com: user does not have permission")));
            }

            if (m_LibType != "forms" && m_LibType != "quicklinks")
            {
                cLibrary.Add(GetFormTeaserData(), "ContentTeaser", null, null);
                cLibrary.Add(CollectMetaField(), "ContentMetadata", null, null);
                cLibrary.Add("", "Image", null, null);
            }

            if (operation == "overwrite")
            {
                m_refContentApi.UpdateLibraryItemByID(cLibrary);
            }
            else
            {
                Ektron.Cms.Library.EkLibrary m_reflib;
                m_reflib = m_refContentApi.EkLibraryRef;
                bool ret;
                ret = m_reflib.AddLibraryItemv2_0(cLibrary, 0);
            }
            string retField = "";
            retField = Request.QueryString["retfield"];

            FolderData f_data = new FolderData();
            f_data = m_refContentApi.GetFolderById(m_folder);
            System.Random rand = new System.Random();
            string file_name = Strings.Replace(cLibrary["LibraryFilename"].ToString(), "\\\\", "/", 1, -1, 0);
            if ("overwrite" == operation && "ContentDesigner" == sEditor)
            {
                file_name += "?n=" + rand.Next(0, 10000);
            }
            //if ((f_data.IsDomainFolder) || (f_data.DomainProduction != "" || f_data.DomainStaging != ""))
            //{
            //    file_name = Strings.Replace(file_name, m_refContentApi.SitePath, "", 1, 1, 0);
            //    if (m_refCommonApi.RequestInformationRef.IsStaging)
            //    {
            //        file_name = (string) ("http://" + f_data.DomainStaging + "/" + file_name);
            //    }
            //    else
            //    {
            //        file_name = (string) ("http://" + f_data.DomainProduction + "/" + file_name);
            //    }

            //}
            string InsertFn = "";
            if ((retField != null)&& retField != "")
            {
                InsertFn = "InserValueToField(\"" + file_name.Replace("\\\\", "/") + "\",\"" + Ektron.Cms.Common.EkFunctions.GetThumbnailForContent(file_name) + "\",\"" + SitePath + "\", \"" + retField + "\");";
            }
            else
            {
                if (sEditor == "JSEditor")
                {
                    if (cLibrary["LibraryType"].ToString()  == "images")
                    {
                        InsertFn = "window.opener.JSEIMGInsert(escape(\'" + file_name + "\'),\'" + Strings.Replace(cLibrary["LibraryTitle"].ToString(), "\'", "\\\'", 1, -1, 0) + "\');self.close();";
                    }
                    else if (cLibrary["LibraryType"].ToString() == "files")
                    {
                        InsertFn = "window.opener.JSEURLInsert(escape(\'" + file_name + "\'),\'" + Strings.Replace((string)(sLinkText != "" ? sLinkText : (cLibrary["LibraryTitle"])), "\'", "\\\'", 1, -1, 0) + "\');self.close();";
                    }
                }
                else
                {
                    InsertFn = "InsertFunction(\"" + file_name + "\", \"" + cLibrary["LibraryTitle"] + "\", \"" + cLibrary["LibraryType"] + "\");self.close();";
                }
            }
            JSInsertFn.Text = "<script language=\"javascript\">" + InsertFn + "</script>";
    }