示例#1
0
        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            selectedItems = new List <string>();
            var postValues = postCollection[postDataKey];

            foreach (var postValue in postValues.Split(','))
            {
                selectedItems.Add(SPEncode.HtmlDecode(postValue));
            }

            fillInValue = postCollection[postDataKey + "$FillInChoiceValue"];
            if (!string.IsNullOrEmpty(fillInValue))
            {
                fillInValue = fillInValue.Trim();
            }

            if (!string.IsNullOrEmpty(fillInValue))
            {
                selectedItems.Add(fillInValue);
            }

            var oldSelectedItems = new List <string>();

            if (!string.IsNullOrEmpty(selectedItemsString))
            {
                oldSelectedItems.AddRange(selectedItemsString.Split(new [] { ";#" }, StringSplitOptions.None));
            }

            // Sort
            selectedItems.Sort();
            oldSelectedItems.Sort();

            return(!selectedItems.SequenceEqual(oldSelectedItems));
        }
        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            var keys = new List <string>(postCollection.AllKeys);

            if (!keys.Contains(postDataKey) && !keys.Contains(postDataKey + "$FillInChoice"))
            {
                return(false);
            }

            var postedValue = postCollection[postDataKey];

            if (string.Equals(postedValue, FillInChoiceValue))
            {
                postedValue = Utilities.Trim(postCollection[postDataKey + "$FillInChoice"]);
            }
            else
            {
                postedValue = SPEncode.HtmlDecode(postedValue);
            }

            if (!string.Equals(postedValue, Value))
            {
                Value = postedValue;
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Gets and ensure the field data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>The field content</returns>
        private string GetFieldData(SPItem item, string fieldName)
        {
            string fieldData = string.Empty;

            if (item[fieldName] != null)
            {
                fieldData = SPEncode.HtmlDecode(item[fieldName].ToString());

                // Dates in ISO8601
                if (_bDateTimeISO8601 &&
                    item.Fields.GetField(fieldName).Type == SPFieldType.DateTime)
                {
                    fieldData = SPUtility.CreateISO8601DateTimeFromSystemDateTime(
                        DateTime.Parse(fieldData, CultureInfo.InvariantCulture).ToUniversalTime().ToLocalTime());
                }
                else
                {
                    // fix: lookup fields
                    if (_bFixLookUp)
                    {
                        if (fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) > 0)
                        {
                            fieldData = fieldData.Substring(fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) + 2);
                        }
                    }
                }
            }
            return(fieldData);
        }
        internal void ProcessPostBack()
        {
            // Get Postback data
            if (Page.IsPostBack)
            {
                // Decode data
                string eventArg = Page.Request["__EVENTARGUMENT"];
                string eventId  = Page.Request["__EVENTTARGET"];
                if (eventArg != null && eventId == ID)
                {
                    _eventArgs = SPEncode.HtmlDecode(eventArg);
                }

                // Get data
                if (!string.IsNullOrEmpty(_eventArgs) &&
                    (_eventArgs.StartsWith("ProCopy|") ||
                     _eventArgs.StartsWith("ProCut|")))
                {
                    PasteHere();
                }

                // Get data
                if (!string.IsNullOrEmpty(_eventArgs) &&
                    (_eventArgs.StartsWith("ProCopyPic|") ||
                     _eventArgs.StartsWith("ProCutPic|")))
                {
                    PastePicsHere();
                }
            }
        }
        /// <summary>
        /// Gets and ensure the field data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>The field content</returns>
        private string GetFieldData(SPItem item, string fieldName)
        {
            string fieldData = string.Empty;

            if (ItemContainsFieldAndData(item, fieldName))
            {
                try
                {
                    fieldData = SPEncode.HtmlDecode(item[fieldName].ToString());
                    fieldData = ProcessFieldData(item, fieldName, fieldData);
                }
                catch (FormatException ex)
                {
                    Debug.WriteLine(fieldName);
                    Debug.WriteLine("GetFieldData " + ex);
                }
            }
            Debug.WriteLine("GetFieldData " + fieldName + "=" + fieldData);
            return(fieldData);
        }
示例#6
0
        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            var keys = new List <string>(postCollection.AllKeys);

            if (!keys.Contains(postDataKey) && !keys.Contains(postDataKey + "$FillInChoice"))
            {
                return(false);
            }

            fillInChoiceSelected = postCollection[postDataKey + "$FillInChoice"] == "FillInButton";

            var selectedItem = fillInChoiceSelected ? postCollection[postDataKey + "$FillInChoiceValue"] : SPEncode.HtmlDecode(postCollection[postDataKey]);

            if (!string.Equals(selectedItem, Convert.ToString(Value)))
            {
                Value = selectedItem;
                return(true);
            }

            return(false);
        }
示例#7
0
 protected override string GetProcessedValue()
 {
     return(SPEncode.HtmlDecode(Value));
 }
        /// <summary>
        /// Does the paste action
        /// </summary>
        private void PastePicsHere()
        {
            // Pro
            // SiteUrl
            // PictureLibrary ID
            // FileUrl
            Debug.WriteLine("** _eventArgs: " + _eventArgs);
            string[] pasteData = _eventArgs.Split('|');

            SPWeb  currWeb = SPContext.Current.Web;
            SPList list    = SPContext.Current.List;


            // Rootfolder contains the current folder
            string destinationFolderUrl = Page.Request.QueryString["RootFolder"];

            // Check for valid url
            // Default views (aka root folders) don´t contain a RootFolder QueryString
            if (string.IsNullOrEmpty(destinationFolderUrl))
            {
                //destinationFolderUrl = currWeb.ServerRelativeUrl + "/" + SPEncode.UrlEncodeAsUrl(list.Title);
                destinationFolderUrl = currWeb.Url + "/" +
                                       SPEncode.UrlEncodeAsUrl(NormalizeUrl(list.RootFolder.ToString()));
                // list.Title
            }

            try
            {
                // Open source site and to get the file or folder
                using (SPSite site = new SPSite(pasteData[1]))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        // Folder object from url
                        // Reopen too get elevated privileges
                        // SPWeb destinationWeb = site.OpenWeb(currWeb.ID);
                        Debug.WriteLine("Destination Folder:" + destinationFolderUrl);
                        SPFolder destinationFolder = currWeb.GetFolder(destinationFolderUrl);

                        Debug.WriteLine("Destination Folder:" + destinationFolderUrl);
                        Debug.WriteLine("Source Site:" + pasteData[1]);
                        Debug.WriteLine("Source List ID:" + pasteData[2]);
                        Debug.WriteLine("Source List ID:" + pasteData[3]);
                        Debug.WriteLine("Source Items IDs:" + pasteData[4]);

                        string[] pictureIds = pasteData[4].Split(';');
                        SPList   sourceList = web.Lists[new Guid(pasteData[2])];

                        // Paste the file

                        foreach (string id in pictureIds)
                        {
                            SPListItem listItem = sourceList.GetItemById(Int32.Parse(id));

                            string itemFolder = web.ServerRelativeUrl + "/" +
                                                listItem.Url.Substring(0,
                                                                       listItem.Url.LastIndexOf('/'));

                            Debug.WriteLine(string.Format("Source Folder {0} - {1}", itemFolder, pasteData[3]));

                            if (itemFolder != SPEncode.HtmlDecode(pasteData[3]))
                            {
                                Guid   guidFile = listItem.File.UniqueId;
                                SPFile file     = web.GetFile(guidFile);

                                Debug.WriteLine("** Coping File");
                                CopyFile(file, destinationFolder);

                                //Delete the file if the action is "Cut"
                                if (pasteData[0].ToLower() == "ProCutPic".ToLower())
                                {
                                    //file.Delete();
                                    file.Recycle();
                                }
                            }
                        }
                    }
                }

                RefreshPage();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }