Esempio n. 1
0
        /// <summary>
        /// Imports an entity from a previous export.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="namespace">The @namespace.</param>
        /// <param name="archiveData">The archive data.</param>
        /// <returns></returns>
        public virtual Entity ImportEntity(string containerTitle, string path, Guid entityId, string @namespace, byte[] archiveData)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                folder = CreateFolderInternal(web, containerTitle, path);
            }

            var docEntityContentTypeId = list.ContentTypes.BestMatch(new SPContentTypeId(Constants.DocumentStoreEntityContentTypeId));

            var properties = new Hashtable
            {
                { "DocumentSetDescription", "Document Store Entity" },
                { "DocumentEntityGuid", entityId.ToString() },
                { "Namespace", @namespace }
            };

            DocumentSet importedDocSet;

            web.AllowUnsafeUpdates = true;
            try
            {
                var currentUser = web.AllUsers[CurrentUserLoginName];
                importedDocSet = DocumentSet.Import(archiveData, entityId.ToString(), folder, docEntityContentTypeId, properties, currentUser);

                //Update with the specified id.
                importedDocSet.Item[SPBuiltInFieldId.Title] = entityId.ToString();
                importedDocSet.Item[Constants.DocumentEntityGuidFieldId] = entityId.ToString();
                importedDocSet.Item.SystemUpdate(false);
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(SPDocumentStoreHelper.MapEntityFromDocumentSet(importedDocSet, null));
        }
Esempio n. 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "";

            try
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                    using (SPWeb web = site.OpenWeb())
                    {
                        string ListId     = Request.Params["ListId"];
                        Guid   id         = new Guid(ListId);
                        SPList sourceList = web.Lists.GetList(id, true);
                        string ItemId     = Request.Params["ItemId"];

                        SPListItem  sourceItem  = sourceList.GetItemById(Convert.ToInt32(ItemId));
                        DocumentSet documentSet = DocumentSet.GetDocumentSet(sourceItem.Folder);

                        SPList targetList = web.Lists[DropDownList1.SelectedItem.Text.ToString()];

                        string sourceCType = sourceItem.ContentType.Name.ToString();
                        //string sourceCTypeParentName = sourceItem.ContentType.Parent.Name;

                        SPContentTypeCollection oCTypeColl = targetList.ContentTypes;
                        StringCollection        Colec      = new StringCollection();
                        foreach (SPContentType conttype in oCTypeColl)
                        {
                            Colec.Add(conttype.Name.ToString());
                        }
                        if (Colec.Contains(sourceCType))
                        {
                            SPContentTypeId contentTypeId   = targetList.ContentTypes[sourceCType].Id;
                            byte[]          documentSetData = documentSet.Export();
                            string          documentSetName = documentSet.Item.Name;
                            SPFolder        targetFolder    = targetList.RootFolder;
                            Hashtable       properties      = sourceItem.Properties;
                            DocumentSet.Import(documentSetData, documentSetName, targetFolder, contentTypeId, properties, web.CurrentUser);

                            try
                            {
                                web.AllowUnsafeUpdates = true;
                                documentSet.VersionCollection.Add(true, "Document set item has been exported to destination library by: " + web.CurrentUser);
                                sourceItem.Update();
                                web.AllowUnsafeUpdates = false;
                            }
                            catch (Exception ex1)
                            {
                                Label1.ForeColor = System.Drawing.Color.Red;
                                Label1.Text      = ex1.Message;
                            }

                            string urlRed = site.Url + "/" + targetList + "/Forms/AllItems.aspx";
                            Response.Redirect(urlRed);
                        }
                        else
                        {
                            Label1.ForeColor = System.Drawing.Color.Red;
                            Label1.Text      = "No content type found. Go to your destination library and add content type.";
                        }
                    }
            }
            catch (Exception ex)
            {
                Label1.ForeColor = System.Drawing.Color.Red;
                Label1.Text      = ex.Message;
            }
        }
Esempio n. 3
0
        public SPDocumentSetInstance Import(Base64EncodedByteArrayInstance bytes, string name, SPFolderInstance parentFolder, object ctid, object properties, object user)
        {
            if (bytes == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A base64 encoded byte array must be supplied as the first argument.");
            }

            if (name.IsNullOrWhiteSpace())
            {
                throw new JavaScriptException(this.Engine, "Error", "The name of the new document set must be specified.");
            }

            if (parentFolder == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The parent folder must be specified.");
            }

            if (ctid == Undefined.Value && properties == Undefined.Value && user == Undefined.Value)
            {
                var r = DocumentSet.Import(bytes.Data, name, parentFolder.Folder);
                if (r == null)
                {
                    return(null);
                }

                return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site,
                                                 parentFolder.Folder.ParentWeb, r));
            }



            var spCtId = ctid as SPContentTypeIdInstance;

            if (ctid == null || ctid == Null.Value || ctid == Undefined.Value || spCtId == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The Content Type Id of the imported document set must be specified.");
            }

            var spUser = user as SPUserInstance;

            if (user == null || user == Null.Value || user == Undefined.Value || spUser == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The user of the imported document set must be specified.");
            }

            var htProperties = new Hashtable();

            if (properties != null && properties != Null.Value && properties != Undefined.Value)
            {
                htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties);
            }

            var result = DocumentSet.Import(bytes.Data, name, parentFolder.Folder, spCtId.ContentTypeId, htProperties, spUser.User);

            if (result == null)
            {
                return(null);
            }

            return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site,
                                             parentFolder.Folder.ParentWeb, result));
        }