CSOM在Farmsolution.
-
10-12-2019 - |
题
我有烦恼让它运行并想问你,如果您知道是否有可能在SP 2013 Farm解决方案中使用CSOM?
我不断得到401未经授权的例外。
此处是如何创建客户端的:
this.webUrl = SPContext.Current.Web.Url;
this.siteUrl = SPContext.Current.Site.Url;
clientContext = new SP.ClientContext(this.webUrl);
clientContext.Credentials = CredentialCache.DefaultNetworkCredentials;
.
因为我想在SharePoint自动软件应用程序和我的农场解决方案之间共享代码,我必须使用CSOM。
解决方案
This won't work because of internal security checks of SharePoint, and deactivating them isn't recommended.
Therefore you abstract your main code and create a semi intelligent data binding layer in your class to load the data. Dynamically loading in the required namespace for reading in the data, by using reflection.
System.Reflection.Assembly asmbly;
asmbly = System.Reflection.Assembly.Load("Microsoft.SharePoint")
object clss;
clss = asb.CreateInstance("Microsoft.SharePoint.Foo")
Yes it would be a little more code, but if you abstract it properly and load the data into a List for example, then this code will be minimal.
Reference - Dynamic Namespace Imports and Switching:
http://www.codeproject.com/Articles/32828/Using-Reflection-to-load-unreferenced-assemblies-a