当前位置: 首页>>代码示例>>C#>>正文


C# SPSite.EnsureUser方法代码示例

本文整理汇总了C#中SPSite.EnsureUser方法的典型用法代码示例。如果您正苦于以下问题:C# SPSite.EnsureUser方法的具体用法?C# SPSite.EnsureUser怎么用?C# SPSite.EnsureUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SPSite的用法示例。


在下文中一共展示了SPSite.EnsureUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSubmitFile

        /// <summary>
        /// OnSubmitFile method for the content organizer
        /// </summary>
        /// <param name="contentOrganizerWeb">The web.</param>
        /// <param name="recordSeries">Record series.</param>
        /// <param name="userName">Submitting user name.</param>
        /// <param name="fileContent">File content.</param>
        /// <param name="properties">File properties.</param>
        /// <param name="finalFolder">The final folder.</param>
        /// <param name="resultDetails">Result processing details.</param>
        /// <returns>The CustomRouterResult.</returns>
        public override CustomRouterResult OnSubmitFile(EcmDocumentRoutingWeb contentOrganizerWeb, string recordSeries, string userName, Stream fileContent, RecordsRepositoryProperty[] properties, SPFolder finalFolder, ref string resultDetails)
        {
            this.ResolveDependencies();

                var web = new SPSite(contentOrganizerWeb.DropOffZoneUrl).OpenWeb();

                // Get routed document properties
                var documentProperties = EcmDocumentRouter.GetHashtableForRecordsRepositoryProperties(
                    properties, recordSeries);

                // Example: Get a conventional field (8553196d-ec8d-4564-9861-3dbe931050c8 = FileLeafRef)
                string originalFileName = documentProperties["8553196d-ec8d-4564-9861-3dbe931050c8"].ToString();

                // EncodedAbsUrl field
                string originalFileUrl = documentProperties["7177cfc7-f399-4d4d-905d-37dd51bc90bf"].ToString();

                // Example: Get the SharePoint user who perform the action
                var user = web.EnsureUser(userName);

                // Example: Deal with errors
                if (originalFileName.ToLower().Contains("error"))
                {
                    // Display error message
                    SPUtility.TransferToErrorPage(
                        string.Format(CultureInfo.InvariantCulture, "This is an error message"));

                    // Save the error file in the Drop Off Library
                    this.SaveDocumentToDropOffLibrary(
                        fileContent,
                        documentProperties,
                        contentOrganizerWeb.DropOffZone,
                        originalFileName,
                        contentOrganizerWeb,
                        user);

                    return CustomRouterResult.SuccessCancelFurtherProcessing;
                }

                // Here is the business logic

                // Example: get a taxonomy field from document properties
                string confidentialityTaxValue = documentProperties[MyFields.MyTaxField.InternalName].ToString();
                string confidentiality = new TaxonomyFieldValue(confidentialityTaxValue).Label;

                // Example: Set a new field to the item
                var indexDate =
                    SPUtility.CreateISO8601DateTimeFromSystemDateTime(
                        DateHelper.GetSharePointDateUtc(web, DateTime.Now));

                // Be careful, if you want to add or modify some properties, use internal GUID instead of InternalName
                if (!documentProperties.ContainsKey(MyFields.MyIndexDate.ID.ToString()))
                {
                    documentProperties.Add(MyFields.MyIndexDate.ID.ToString(), indexDate);
                }
                else
                {
                    documentProperties[MyFields.MyIndexDate.ID.ToString()] = indexDate;
                }

                // Save the file in the final destination. You can get the newly created file here and apply further actions.
                var file = EcmDocumentRouter.SaveFileToFinalLocation(
                contentOrganizerWeb,
                finalFolder,
                fileContent,
                originalFileName,
                originalFileUrl,
                documentProperties,
                user,
                true,
                string.Empty);

                web.Dispose();

                return CustomRouterResult.SuccessContinueProcessing;
        }
开发者ID:GSoft-SharePoint,项目名称:Dynamite-2010-Example-ContentOrganizer,代码行数:86,代码来源:MyRouter1.cs


注:本文中的SPSite.EnsureUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。