就我个人而言,我制作HttpHandlers。我将它们安装在SharePoint isapi文件夹和GAC中,我可以像调用owssvr.dll一样调用它们。 http://servername/_vti_bin/myhttphandelr.dll
传递查询字符串变量或从jquery ajax调用它。您可以使用httpcontext并从中创建spcontext,并可以访问SharePoint中当前位置的各种信息。然后你可以javascriptserialize这些对象并将它们作为JSON传递。寻找一些代码...挂上...我不能把所有的代码,但这应该让你关闭。我用它来添加一个子菜单到上下文菜单,以允许用户删除或重命名一个文件,如果他们上传到一个库,它是版本1.0,并从库中收集文件,并创建一个带有选定文件的eml文件(s)作为附件。我们不会给我们的用户正常删除权限。需要指出的是,现在您可以使用SharePoint所需的信息创建一个类,并将其作为JSON传递。这是我唯一的缺点,如果你对dll进行任何更改,iisreset是必需的。 无论如何,我每天晚上都会安排一次iisreset,以保持新鲜感并避免内存膨胀。我第二天来,我的变化就在那里。最酷的是,spcontext具有关于调用SharePoint的当前位置的信息。所以,http://servername/_vti_bin/myhttphandelr.dll vs http://servername/subsite/library/_vti_bin/myhttphandelr.dll
我可能会添加。不要尝试序列化SharePoint对象。一个是巨大而复杂的物体。二,我不认为它们被标记为可序列化。只需创建自己的类,并使用SharePoint对象中需要的值填充它。
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using System.Web;
using System.Web.Script.Serialization;
using ADODB;
using interop.cdosys;
using Microsoft.SharePoint;
namespace owssvr2
{
public class OWSsvr2 : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
private string cmd;
ctx ctx = new ctx();
private string currentuser;
private SPContext SPcontext;
private HttpContext cntx;
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
SPcontext = SPContext.GetContext(context); <-- Gets spcontext from the httpcontext
cntx = context;
ctx = GetData(context.Request); <-- I parse some information from the request to use in my app
cmd = ctx.Cmd;
ctx.User = context.User.Identity.Name;
currentuser = context.User.Identity.Name;
switch (cmd)
{
case "Delete":
Delete();
context.Response.Redirect(ctx.NextUsing);
break;
case "HasRights":
HasRights();
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
string serEmployee = javaScriptSerializer.Serialize(ctx);
context.Response.Write(serEmployee);
context.Response.ContentType = "application/json; charset=utf-8";
break;
case "Rename":
Rename(context);
//context.Response.Redirect(context.Request["NextUsing"]);
break;
case "SendSingleFile":
try
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.BufferOutput = true;
ADODB.Stream stream = SendSingleFile(context.Request["URL"]);
stream.Type = StreamTypeEnum.adTypeBinary;
stream.Position = 0;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=Email.eml");
IStream iStream = (IStream)stream;
byte[] byteArray = new byte[stream.Size];
IntPtr ptrCharsRead = IntPtr.Zero;
iStream.Read(byteArray, stream.Size, ptrCharsRead);
context.Response.BinaryWrite(byteArray);
context.Response.End();
}
catch(Exception ex) {context.Response.Write(ex.Message.ToString()); }
break;
case "SendMultiFile":
try
{
//SendMultiFile(context.Request["IDs"]);
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.BufferOutput = true;
ADODB.Stream stream = SendMultiFile(context.Request["IDs"]);
stream.Type = StreamTypeEnum.adTypeBinary;
stream.Position = 0;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=Email.eml");
IStream iStream = (IStream)stream;
byte[] byteArray = new byte[stream.Size];
IntPtr ptrCharsRead = IntPtr.Zero;
iStream.Read(byteArray, stream.Size, ptrCharsRead);
context.Response.BinaryWrite(byteArray);
context.Response.End();
}
catch(Exception ex) {context.Response.Write("There was an error getting the files. </br>" + ex.Message.ToString()); }
break;
case "FileInfo":
JavaScriptSerializer javaScriptSerializer1 = new JavaScriptSerializer();
string serEmployee1 = javaScriptSerializer1.Serialize(FileInfo(context));
context.Response.Write(serEmployee1);
context.Response.ContentType = "application/json; charset=utf-8";
break;
case "UsersInGroups":
UsersInGroups ug = new UsersInGroups(context, context.Request["job"],context.Request["groups"]);
break;
}
}
您是否考虑过使用sp.js公开csom api over javascript? –
我该怎么做。我不是一个SharePoint专家。 – JeremyA1
但你确实知道JavaScript,在这种情况下你的技能水平是什么? –