好吧,這就是我想要做的。從SharePoint中的JavaScript調用C#代碼
我有這個自定義操作(我的SharePoint功能區上的按鈕)。這應該調用一個Javascript,它反過來應該調用一個C#代碼。
我有以下幾點:
<CustomAction
Id="Ribbon.Documents.DocsetZip"
Title="Download Document Set as ZIP"
RegistrationType="ContentType"
RegistrationId="0x0120D520"
Location="CommandUI.Ribbon"
>
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Documents.Share.Controls._children">
<Button Id="Ribbon.Document.Share.DownasZip"
Sequence="20"
Command="Ribbon.ManageDocumentSet.MDS.Manage.DownZip"
Alt="Download as ZIP"
Image16by16="/_layouts/images/zipfile16x.png"
Image32by32="/_layouts/images/zipfile32x.png"
LabelText="Download as ZIP file"
ToolTipTitle="Download as ZIP file"
ToolTipDescription="Compress the document set and download"
TemplateAlias="o1"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Ribbon.ManageDocumentSet.MDS.Manage.DownZip"
CommandAction="javascript:__doPostBack('DownloadZipDelegateEvent', '')" />
</CommandUIHandlers>
</CommandUIExtension>
,我有一個類:
public class MyRibbonDelegateClass : WebControl
{
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
base.OnLoad(e);
if (this.Page.Request["__EVENTTARGET"] == "DownloadZipDelegateEvent")
{
using (TextWriter writer = File.CreateText("C:\\temp\\perl.txt"))
{
//
// Write one line.
//
writer.WriteLine("First line");
//
// Write two strings.
//
writer.Write("A ");
writer.Write("B ");
//
// Write the default newline.
//
writer.Write(writer.NewLine);
}
}
}
看來我的代碼得到執行,但我找不到我的文件。 我錯過了什麼?
但我實際上應該從上一個按鈕,我加入自己的SharePoint的帶狀點擊調用C#。所以不是從我自己創建的頁面開始的。 – 2015-03-13 13:40:24