【发布时间】:2013-08-06 23:19:55
【问题描述】:
该项目的基本概念是它访问 SharePoint,验证某个文件是否存在,验证该文件没有被另一个用户锁定,然后,如果满足这两个条件,excel 打开文件并使用它,然后保存文件并再次关闭它。
问题在于程序访问 SharePoint 并运行验证步骤。最初,我的第一次破解是直接从 VBA 使用 SOAP,直到微软决定从 2010 年将 SharePoint 降级到 2013 之前,它运行良好,这意味着现在,我正在使用 Visual Studio 和 C# 来完成同样的事情SOAP 是在 SP2010 做的。
我已经尝试实现此处找到的代码:http://www.vrdmn.com/2013/01/authenticating-net-client-object-model.html,但是我无法让它工作。我所做设法开始工作的是 2010 身份验证模型,它会弹出一个浏览器窗口,检查有效的 cookie,如果找到它们,则读取 cookie,否则提示用户登录 SharePoint然后关闭浏览器并继续。
public CookieCollection Show()
{
if (string.IsNullOrEmpty(this.LoginPageUrl)) throw new ApplicationException(Constants.MSG_NOT_CLAIM_SITE);
// navigate to the login page url.
this.webBrowser.Navigate(this.LoginPageUrl);
DisplayLoginForm = new Form();
DisplayLoginForm.SuspendLayout();
// size the login form
int dialogWidth = Constants.DEFAULT_POP_UP_WIDTH;
int dialogHeight = Constants.DEFAULT_POP_UP_HEIGHT;
if (PopUpHeight != 0 && PopUpWidth != 0)
{
dialogWidth = Convert.ToInt32(PopUpWidth);
dialogHeight = Convert.ToInt32(PopUpHeight);
}
DisplayLoginForm.Width = dialogWidth;
DisplayLoginForm.Height = dialogHeight;
DisplayLoginForm.Text = this.fldTargetSiteUrl;
DisplayLoginForm.Controls.Add(this.webBrowser);
DisplayLoginForm.ResumeLayout(false);
//DisplayLoginForm.Show();
Application.Run(DisplayLoginForm);
// see ClaimsWebBrowser_Navigated event
//DisplayLoginForm.Dispose();
return this.fldCookies;
}
问题来自 Application.Run(DisplayLoginForm)。如果我逐行执行代码,一切正常,并且在我的 VBA 代码中得到我需要的结果。但是,如果我使用 F5 运行程序(通过在调试模式或发布模式下构建它), Application.Run(DisplayLoginForm) 会在 cookie jar (我的术语,并且很可能不是计算机术语)已检查有效 cookie。
您可以在代码中看到,我尝试使用 DisplayLoginForm.Show();而不是 Application.Run,但是我不断获得对我要查找的文件的空引用,因此这种方法也不起作用。
那么问题来了:
我该如何弹出一个网络浏览器(显然是设置为 Windows 窗体)、查找 cookie、在需要时提示用户、关闭网络浏览器并保持足够长的时间以返回适当的值(file.exists 和 file.islockedbyuser.email,这两个函数都在 VBA 调用的函数中,都可以正常工作)excel,然后在不关闭 Excel 的情况下完成程序?
【问题讨论】:
-
我想我已经找到了一个可能的解决方案——在第二个线程中打开浏览器。我会解决它,看看会发生什么。同时,如果有人有建议,我很乐意阅读。
标签: c# excel sharepoint dll claims-based-identity