Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WBFarm farm = WBFarm.Local;

                SPSite site = SPContext.Current.Site;

                RecordsLibraryToUse.DataSource = WBFWebPartsUtils.GetRecordsLibraryOptions();
                RecordsLibraryToUse.DataBind();
                RecordsLibraryToUse.WBxSafeSetSelectedValue(WBFWebPartsUtils.GetRecordsLibraryToUse(site));
                LocalPublicLibraryURL.Text = WBFWebPartsUtils.GetLocalPublicLibraryURL(site);

                UseExtranetLibrary.Checked   = WBFWebPartsUtils.UseExtranetLibrary(site);
                LocalExtranetLibraryURL.Text = WBFWebPartsUtils.GetLocalExtranetLibraryURL(site);

                ShowFileIcons.Checked   = WBFWebPartsUtils.ShowFileIcons(site);
                ShowKBFileSize.Checked  = WBFWebPartsUtils.ShowKBFileSize(site);
                ShowDescription.Checked = WBFWebPartsUtils.ShowDescription(site);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            webPart = this.Parent as PickRelatedDocuments;

            SPWebPartManager webPartManager = (SPWebPartManager)WebPartManager.GetCurrentWebPartManager(this.Page);

            Guid WebPartGuid = webPartManager.GetStorageKey(webPart);

            WebPartUniqueID = WebPartGuid.ToString().Replace("-", String.Empty);;

            //EditRelatedDocumentsButton.OnClientClick = "WorkBoxFramework_editRelatedDocuments(WBF_EditDialogCallback" + WebPartUniqueID + ", \"" + webPart.PickedDocumentsDetails + "\"); return false;";

            String[] detailsToSave = new String[3];

            detailsToSave[0] = WBUtils.ReplaceDelimiterCharacters(webPart.Title);
            detailsToSave[1] = WBUtils.ReplaceDelimiterCharacters(webPart.RelatedDocumentsDescription);
            detailsToSave[2] = WBUtils.ReplaceDelimiterCharacters(webPart.PickedDocumentsDetails.WBxTrim());

            String currentDetails         = String.Join(",", detailsToSave);
            String pickedDocumentsDetails = webPart.PickedDocumentsDetails.WBxTrim();


            if (IsPostBack)
            {
                if (NeedToSave.Value == "true")
                {
                    string[] newDetails = NewRelatedDocumentsDetails.Value.WBxTrim().Split(',');

                    if (newDetails.Length != 3)
                    {
                        WBLogging.Debug("The details sent to this page have the wrong structure: " + NewRelatedDocumentsDetails.Value);
                        Description.Text = "(the web part has not yet been edited).";
                        return;
                    }

                    if (WBFWebPartsUtils.ShowDescription(SPContext.Current.Site))
                    {
                        webPart.Title = WBUtils.PutBackDelimiterCharacters(newDetails[0]);
                        webPart.RelatedDocumentsDescription = WBUtils.PutBackDelimiterCharacters(newDetails[1]);
                    }
                    webPart.PickedDocumentsDetails = WBUtils.PutBackDelimiterCharacters(newDetails[2]);

                    webPartManager.SaveChanges(WebPartGuid);

                    SPContext.Current.File.Update();
                    SPContext.Current.Web.Update();

                    currentDetails         = NewRelatedDocumentsDetails.Value.WBxTrim();
                    pickedDocumentsDetails = webPart.PickedDocumentsDetails;
                }
            }

            if (!String.IsNullOrEmpty(currentDetails) && !currentDetails.Contains(","))
            {
                WBLogging.Generic.Unexpected("The PickRelatedDocuments web part had an odd value: " + currentDetails);
                currentDetails = "";
            }

            Description.Text = WBUtils.MaybeAddParagraphTags(webPart.RelatedDocumentsDescription);
            if (!String.IsNullOrEmpty(Description.Text) && WBFWebPartsUtils.ShowDescription(SPContext.Current.Site))
            {
                showDescription = true;
            }


            if ((SPContext.Current.FormContext.FormMode == SPControlMode.Edit) ||
                (webPartManager.DisplayMode == WebPartManager.EditDisplayMode))
            {
                EditPanel.Visible = true;
                InEditMode        = true;
                EditRelatedDocumentsButton.OnClientClick = "WorkBoxFramework_editRelatedDocuments(WBF_EditDialogCallback" + WebPartUniqueID + ", \"" + stripDownDetailsForEditing(currentDetails) + "\"); return false;";
            }
            else
            {
                EditPanel.Visible = false;
                EditRelatedDocumentsButton.OnClientClick = "";
            }



            WBLogging.Debug("PickRelatedDocuments currentDetails: " + currentDetails);


            if (String.IsNullOrEmpty(pickedDocumentsDetails))
            {
                DocumentList.Text = "<ul><li>(No documents picked)</li></ul>";
                DocumentsToView   = false;
                return;
            }

            try
            {
                string[] documentsDetailsArray = pickedDocumentsDetails.Split(';');

                String recordsLibraryURL = WBFWebPartsUtils.GetRecordsLibraryURL(SPContext.Current.Site);

                using (SPSite site = new SPSite(recordsLibraryURL))
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList library = web.GetList(recordsLibraryURL);

                        String html = "<ul>\n";

                        foreach (string documentDetails in documentsDetailsArray)
                        {
                            string[] documentDetailsArray = documentDetails.Split('|');

                            if (documentDetailsArray.Length != 4)
                            {
                                WBLogging.Generic.Unexpected("Badly formatted document details in PickRelatedDocuments web part: " + currentDetails + " - Ignoring these details");
                                continue;
                            }

                            string zone     = documentDetailsArray[0];
                            string recordID = documentDetailsArray[1];
                            string sourceID = documentDetailsArray[2];
                            string filename = documentDetailsArray[3];

                            SPListItem item = WBFWebPartsUtils.GetRecord(site, web, library, zone, recordID);

                            if (item == null)
                            {
                                if (InEditMode)
                                {
                                    html += "<li><i>(Could not find document)</i></li>";
                                }
                            }
                            else
                            {
                                DocumentsToView = true;

                                string title = item.WBxGetAsString(WBColumn.Title);
                                if (String.IsNullOrEmpty(title))
                                {
                                    title = Path.GetFileNameWithoutExtension(item.Name);
                                }

                                string extension = Path.GetExtension(item.Name).Replace(".", "").ToUpper();

                                string additionalText = "";

                                if (WBFWebPartsUtils.ShowKBFileSize(SPContext.Current.Site))
                                {
                                    long fileLength = (item.File.Length / 1024);
                                    additionalText = ", " + fileLength + "KB";
                                }

                                if (WBFWebPartsUtils.ShowFileIcons(SPContext.Current.Site))
                                {
                                    title = String.Format("<img src=\"{0}\" alt=\"{1}\" class=\"wbf-picked-doc-image\"/> {1}",
                                                          WBUtils.DocumentIcon16(item.Name),
                                                          title);
                                }

                                html += "<li><a target=\"_blank\" href=\"" + item.WBxGetAsString(WBColumn.EncodedAbsoluteURL) + "\">" + title + "</a> <span>(" + extension + additionalText + ")</span></li>";
                            }
                        }

                        html += "</ul>\n";

                        DocumentList.Text = html;
                    }
            }
            catch (Exception exception)
            {
                if (InEditMode)
                {
                    DocumentList.Text = "An error occurred: " + exception.Message;
                }
                else
                {
                    DocumentsToView = false;
                }
            }
        }