コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            recordID = Page.Request.QueryString["RecordID"];

            //            _listId = Page.Request.QueryString["ListId"];
            _itemId = Page.Request.QueryString["ItemId"];


            if (String.IsNullOrEmpty(recordID) && String.IsNullOrEmpty(_itemId))
            {
                _recordItem = null;
                return;
            }


            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                String recordsLibraryURL = WBFWebPartsUtils.GetRecordsLibraryURL(SPContext.Current.Site);

                using (_recordsSite = new SPSite(recordsLibraryURL))
                    using (_recordsWeb = _recordsSite.OpenWeb())
                    {
                        _recordsLibrary = _recordsWeb.GetList(recordsLibraryURL);

                        if (String.IsNullOrEmpty(_itemId))
                        {
                            _recordItem = WBFWebPartsUtils.GetRecord(_recordsSite, _recordsWeb, _recordsLibrary, "", recordID);
                        }
                        else
                        {
                            _recordItem = _recordsLibrary.GetItemById(Convert.ToInt32(_itemId));
                            recordID    = _recordItem.WBxGetAsString(WBColumn.RecordID);
                        }

                        recordURL            = _recordsWeb.ServerRelativeUrl + "/" + _recordItem.Url;
                        recordURLToSearchFor = _recordItem.Url.Substring(_recordItem.ParentList.RootFolder.Url.Length);


                        if (_recordItem != null)
                        {
                            recordTitle = _recordItem.Title;
                            recordName  = _recordItem.Name;
                        }
                    }
            });
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            webPart = this.Parent as PickedDocumentsGroup;

            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[5];

            detailsToSave[0] = WBUtils.ReplaceDelimiterCharacters(webPart.Title);
            detailsToSave[1] = WBUtils.ReplaceDelimiterCharacters(webPart.DocumentsGroupDescription);
            detailsToSave[2] = WBUtils.ReplaceDelimiterCharacters(webPart.DocumentsGroupSubjectTags);
            detailsToSave[3] = WBUtils.ReplaceDelimiterCharacters(webPart.DocumentsGroupCoverage);
            detailsToSave[4] = WBUtils.ReplaceDelimiterCharacters(webPart.PickedDocumentsDetails.WBxTrim());

            String currentDetails = String.Join(",", detailsToSave);

            WBLogging.Debug("Current details: " + currentDetails);

            if (IsPostBack)
            {
                if (NeedToSave.Value == "true")
                {
                    WBLogging.Debug("Trying to save value: " + NewDocumentsGroupDetails.Value);

                    string[] newDetails = NewDocumentsGroupDetails.Value.WBxTrim().Split(',');

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


                    webPart.Title = WBUtils.PutBackDelimiterCharacters(newDetails[0]);
                    webPart.DocumentsGroupDescription = WBUtils.PutBackDelimiterCharacters(newDetails[1]);
                    webPart.DocumentsGroupSubjectTags = WBUtils.PutBackDelimiterCharacters(newDetails[2]);
                    webPart.DocumentsGroupCoverage    = WBUtils.PutBackDelimiterCharacters(newDetails[3]);
                    webPart.PickedDocumentsDetails    = WBUtils.PutBackDelimiterCharacters(newDetails[4]);

                    webPartManager.SaveChanges(WebPartGuid);

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

                    currentDetails = NewDocumentsGroupDetails.Value.WBxTrim();

                    WBLogging.Debug("New current details: " + currentDetails);
                }
            }

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

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



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


            Title.Text       = webPart.Title;
            Description.Text = WBUtils.MaybeAddParagraphTags(webPart.DocumentsGroupDescription);

            WBTermCollection <WBTerm> allSubjects = new WBTermCollection <WBTerm>(null, webPart.DocumentsGroupSubjectTags);

            SubjectTags.Text = allSubjects.Names();
            Coverage.Text    = webPart.DocumentsGroupCoverage;


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

            String extranetRecordsLibraryURL = WBFWebPartsUtils.GetExtranetLibraryURL(SPContext.Current.Site);

            SPSite extranetRecordsSite    = null;
            SPWeb  extranetRecordsWeb     = null;
            SPList extranetRecordsLibrary = null;

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

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

                using (SPSite publicRecordsSite = new SPSite(publicRecordsLibraryURL))
                    using (SPWeb publicRecordsWeb = publicRecordsSite.OpenWeb())
                    {
                        SPList publicRecordsLibrary = publicRecordsWeb.GetList(publicRecordsLibraryURL);

                        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 = null;

                            if (zone == "Public Extranet")
                            {
                                if (extranetRecordsLibrary == null)
                                {
                                    extranetRecordsSite    = new SPSite(extranetRecordsLibraryURL);
                                    extranetRecordsWeb     = extranetRecordsSite.OpenWeb();
                                    extranetRecordsLibrary = extranetRecordsWeb.GetList(extranetRecordsLibraryURL);
                                }

                                item = WBFWebPartsUtils.GetRecord(extranetRecordsSite, extranetRecordsWeb, extranetRecordsLibrary, zone, recordID);
                            }
                            else
                            {
                                item = WBFWebPartsUtils.GetRecord(publicRecordsSite, publicRecordsWeb, publicRecordsLibrary, 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 = "";
                                long   fileLength     = (item.File.Length / 1024);
                                additionalText = ", " + fileLength + "KB";

                                if (item.WBxHasValue(WBColumn.ReferenceDate))
                                {
                                    DateTime referenceDate       = (DateTime)item.WBxGet(WBColumn.ReferenceDate);
                                    string   referenceDateString = string.Format("{0}-{1}-{2}",
                                                                                 referenceDate.Year.ToString("D4"),
                                                                                 referenceDate.Month.ToString("D2"),
                                                                                 referenceDate.Day.ToString("D2"));

                                    additionalText += ", " + referenceDateString;
                                }

                                html += String.Format("<li><img src=\"{0}\" alt=\"{1}\"/><a target=\"_blank\" href=\"{2}\">{1}</a> <span>({3})</span></li>",
                                                      WBUtils.DocumentIcon16(item.WBxGetAsString(WBColumn.Name)),
                                                      title,
                                                      item.WBxGetAsString(WBColumn.EncodedAbsoluteURL),
                                                      extension + additionalText);
                            }
                        }

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

                        DocumentsList.Text = html;
                    }
            }
            catch (Exception exception)
            {
                if (InEditMode)
                {
                    DocumentsList.Text = "An error occurred: " + exception.Message;
                }
                else
                {
                    DocumentsToView = false;
                }
            }
            finally
            {
                if (extranetRecordsWeb != null)
                {
                    extranetRecordsWeb.Dispose();
                }
                if (extranetRecordsSite != null)
                {
                    extranetRecordsSite.Dispose();
                }
            }
        }
コード例 #3
0
        public TableRow CreateEditableTableRow(SPSite site, SPWeb web, SPList library, int index, String details, List <String> refreshedDocumentsDetailsList)
        {
            TableRow row = new TableRow();

            row.ID       = MakeControlID(index, "row");
            row.CssClass = "wbf-edit-action-row";

            //WBLogging.Debug("Just starting with details: " + details);

            string[] parts = details.Split('|');

            string zone     = parts[0];
            string recordID = parts[1];

            //WBLogging.Debug("Here");


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

            if (recordItem == null)
            {
                return(row);
            }

            // OK so we're actually going to refresh the details with the values from the record:
            details = String.Format("{0}|{1}|{2}|{3}",
                                    zone, recordID, "Ignore", recordItem.Name.WBxTrim().Replace(";", "-").Replace("|", "-")
                                    );

            refreshedDocumentsDetailsList.Add(details);

            String displayName = recordItem.WBxGetAsString(WBColumn.Title);

            if (String.IsNullOrEmpty(displayName))
            {
                displayName = recordItem.WBxGetAsString(WBColumn.Name);
            }

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

            //WBLogging.Debug("And Here");


            Image image = new Image();

            image.ImageUrl = WBUtils.DocumentIcon16(recordItem.Name);
            image.Width    = Unit.Pixel(16);
            image.Height   = Unit.Pixel(16);
            row.WBxAddInTableCell(image);


            Label label = new Label();

            label.Text = recordItem.WBxGetAsString(WBColumn.Title);
            row.WBxAddInTableCell(label);

            label      = new Label();
            label.Text = recordItem.WBxGetAsString(WBColumn.Name);
            row.WBxAddInTableCell(label);


            Label extensionLabel = new Label();

            extensionLabel.Text = extension;
            row.WBxAddInTableCell(extensionLabel);

            //WBLogging.Debug("As far as Here");


            Button upButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "UpButton"));

            upButton.Text            = "/\\";
            upButton.CommandName     = "Up";
            upButton.CommandArgument = index.ToString();
            upButton.Command        += new CommandEventHandler(upButton_OnClick);

            Button downButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "DownButton"));

            downButton.Text            = "\\/";
            downButton.CommandName     = "Down";
            downButton.CommandArgument = index.ToString();
            downButton.Command        += new CommandEventHandler(downButton_OnClick);


            Button replaceButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "ReplaceButton"));

            replaceButton.Text          = "Replace";
            replaceButton.OnClientClick = "WorkBoxFramework_pickADocument(" + index + "); return false;";

            Button removeButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "RemoveButton"));

            removeButton.Text          = "Remove";
            removeButton.OnClientClick = "WBF_DeleteRow(" + index + ",\"" + recordItem.Name + "\"); return false;";

            HiddenField documentDetails = (HiddenField)row.WBxAddWithIDInTableCell(new HiddenField(), MakeControlID(index, "DocumentDetails"));

            //WBLogging.Debug("Really Here");


            if (!IsPostBack)
            {
                documentDetails.Value = details;
            }

            return(row);
        }
コード例 #4
0
        public TableRow CreateEditableTableRow(SPSite site, SPWeb web, SPList library, int index, String details)
        {
            TableRow row = new TableRow();

            row.ID       = MakeControlID(index, "row");
            row.CssClass = "wbf-edit-action-row";

            string[] parts = details.Split('|');

            string zone     = parts[0];
            string recordID = parts[1];

            SPListItem recordItem = null;

            if (zone == "Public Extranet")
            {
                if (extranetRecordsLibrary == null)
                {
                    string extranetRecordsLibraryURL = WBFWebPartsUtils.GetExtranetLibraryURL(SPContext.Current.Site);
                    extranetRecordsSite    = new SPSite(extranetRecordsLibraryURL);
                    extranetRecordsWeb     = extranetRecordsSite.OpenWeb();
                    extranetRecordsLibrary = extranetRecordsWeb.GetList(extranetRecordsLibraryURL);
                }

                recordItem = WBFWebPartsUtils.GetRecord(extranetRecordsSite, extranetRecordsWeb, extranetRecordsLibrary, zone, recordID);
            }
            else
            {
                recordItem = WBFWebPartsUtils.GetRecord(site, web, library, zone, recordID);
            }


            if (recordItem == null)
            {
                return(row);
            }

            String displayName = recordItem.WBxGetAsString(WBColumn.Title);

            if (String.IsNullOrEmpty(displayName))
            {
                displayName = recordItem.WBxGetAsString(WBColumn.Name);
            }

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

            Image image = new Image();

            image.ImageUrl = WBUtils.DocumentIcon16(recordItem.Name);
            image.Width    = Unit.Pixel(16);
            image.Height   = Unit.Pixel(16);
            row.WBxAddInTableCell(image);


            Label label = new Label();

            label.Text = recordItem.WBxGetAsString(WBColumn.Title);
            row.WBxAddInTableCell(label);

            label      = new Label();
            label.Text = recordItem.WBxGetAsString(WBColumn.Name);
            row.WBxAddInTableCell(label);


            Label extensionLabel = new Label();

            extensionLabel.Text = extension;
            row.WBxAddInTableCell(extensionLabel);


            Button upButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "UpButton"));

            upButton.Text            = "/\\";
            upButton.CommandName     = "Up";
            upButton.CommandArgument = index.ToString();
            upButton.Command        += new CommandEventHandler(upButton_OnClick);

            Button downButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "DownButton"));

            downButton.Text            = "\\/";
            downButton.CommandName     = "Down";
            downButton.CommandArgument = index.ToString();
            downButton.Command        += new CommandEventHandler(downButton_OnClick);


            Button replaceButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "ReplaceButton"));

            replaceButton.Text          = "Replace";
            replaceButton.OnClientClick = "WorkBoxFramework_pickADocument(" + index + "); return false;";

            Button removeButton = (Button)row.WBxAddWithIDInTableCell(new Button(), MakeControlID(index, "RemoveButton"));

            removeButton.Text          = "Remove";
            removeButton.OnClientClick = "WBF_DeleteRow(" + index + ",\"" + recordItem.Name + "\"); return false;";

            HiddenField documentDetails = (HiddenField)row.WBxAddWithIDInTableCell(new HiddenField(), MakeControlID(index, "DocumentDetails"));


            if (!IsPostBack)
            {
                documentDetails.Value = details;
            }

            return(row);
        }
コード例 #5
0
        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;
                }
            }
        }