在Visual Studio中创建Sharepoint设计器操作 [英] Creat a Sharepoint designer Action in Visual Studio

查看:113
本文介绍了在Visual Studio中创建Sharepoint设计器操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,但是当我运行项目时。错误2当前上下文中不存在名称InitializeComponent。有人可以帮我实现InitializeComponent();请求来源

http://aroundsharepoint.blogspot.mx/2011/01/workflow-action-attach-document-to.html [ ^ ]



 使用系统; 
使用 System.ComponentModel;
使用 System.ComponentModel.Design;
使用 System.Collections;
使用 System.Linq;
使用 System.IO;
使用 Microsoft.SharePoint;
使用 System.Workflow.ComponentModel.Compiler;
使用 System.Workflow.ComponentModel.Serialization;
使用 System.Workflow.ComponentModel;
使用 System.Workflow.ComponentModel.Design;
使用 System.Workflow.Runtime;
使用 System.Workflow.Activities;
使用 Microsoft.SharePoint.WorkflowActions;


命名空间 AttachDocToItemProject
{
public partial class AttachDocToItem:Activity
{

public static DependencyProperty LibIdProperty = DependencyProperty.Register( LibId typeof string ), typeof (AttachDocToItem));
public static DependencyProperty ListIdProperty = DependencyProperty.Register( ListId typeof string ), typeof (AttachDocToItem));
public static DependencyProperty DocItemProperty = DependencyProperty.Register( DocItem typeof Int32 ), typeof (AttachDocToItem));
public static DependencyProperty ListItemProperty = DependencyProperty.Register( ListItem typeof Int32 ), typeof (AttachDocToItem));
public static DependencyProperty __ContextProperty = DependencyProperty.Register( __ Context typeof (WorkflowContext), typeof运算(AttachDocToItem));

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[可浏览( true )]
[描述( 存储将附加到项目的文档的文档库的ID )]
public string LibId
{
get { return (( string )( base .GetValue(AttachDocToItem.LibIdProperty))); }
set { base .SetValue(AttachDocToItem.LibIdProperty,); }
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[可浏览( true )]
[描述( 保留项目的列表的ID文档将附加到)]
public string ListId
{
get { return (( string )( base .GetValue(AttachDocToItem.ListIdProperty))); }
set { base .SetValue(AttachDocToItem.ListIdProperty,); }
}

[描述( 列表项的ID,文档将附加到)]
[ValidationOption(ValidationOption.Required)]
[可浏览( true )]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public Int32 ListItem
{
get { return (( Int32 )( base .GetValue(AttachDocToItem.ListItemProperty))); }
set { base .SetValue(AttachDocToItem.ListItemProperty,); }
}

[描述( 文档项目的ID,文档将附加到)]
[ValidationOption(ValidationOption.Required)]
[可浏览( true )]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public Int32 DocItem
{
get { return (( Int32 )( base .GetValue(AttachDocToItem.DocItemProperty))); }
set { base .SetValue(AttachDocToItem.DocItemProperty,); }
}

[描述( 上下文)]
[ValidationOption(ValidationOption.Required)]
[可浏览( true )]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public WorkflowContext __Context
{
get { return ((WorkflowContext)( base .GetValue(__ ContextProperty))); }
set { base .SetValue(__ ContextProperty,); }
}


受保护 覆盖 ActivityExecutionStatus执行(ActivityExecutionContext executionContext)
{
try
{

__Context.Web.AllowUnsafeUpdates = ;

Guid id = new Guid(ListId);
SPList list = __Context.Web.Lists [id];
Guid做了= Guid(LibId);
SPList docLib = __Context.Web.Lists [did];
SPListItem sourceItem = docLib.GetItemById(DocItem);
SPFile sourceDoc = sourceItem.File;
byte [] fichierbyte = sourceDoc.OpenBinary();

SPListItem destinationItem = list.GetItemById(ListItem);
destinationItem.Attachments.Add(sourceItem.Name,fichierbyte);
destinationItem.Update();
return ActivityExecutionStatus.Closed;

}
catch (例外情况)
{

return ActivityExecutionStatus.Faulting;
throw new 异常(Ex.Message + &&&& + Ex.StackTrace);

}
最后
{

}
return ActivityExecutionStatus.Closed;
}

public AttachDocToItem()
{
InitializeComponent();
}

}
}



 <?  xml     version   =  1.0   < span class =code-summarycomment> encoding   =  utf-8  >  

< WorkflowInfo >
< 操作 顺序 = 然后 并行 = >
< 操作 名称 = 将文档附加到项目

ClassName = AttachDocToItem

程序集 = AttachDocToItem ,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 4f4f4b70dd2f12d2

< span class =code-attribute>
AppliesTo = all 类别 = < span class =code-keyword>>
< RuleDesigner 句子 = 将%1附加到%2 >
< FieldBind 文本 = 此文档 字段 = LibId,DocItem DesignerType = ChooseDoclibItem Id < span class =code-keyword> = 1 / >
< FieldBind 文字 = 此项 字段 = ListId,ListItem < span class =code-attribute> DesignerType = ChooseListItem Id = 2 / >
< / RuleDesigner >
< 参数 > ;
< 参数 名称 = __ Context 类型 = Microsoft.SharePoint.WorkflowActions.WorkflowContext,Microsoft.SharePoint.WorkflowActions 方向 = / >
< 参数 名称 = LibId 类型 = System.String,mscorlib 方向 = InitialBinding = < span class =code-keyword> __ list / >
< 参数 名称 = DocItem 类型 = System.Int32 ,mscorlib 方向 = InitialBinding = __ item DesignerType = ListItem 描述 < span class =code-keyword> = 此操作使用的列表项的ID。 / >
< ; 参数 名称 < span class =code-keyword> = ListId 类型 = System.String,mscorlib 方向 = / >
< 参数 名称 = ListItem 类型 = System.Int32,mscorlib 方向 = DesignerType = ListItem 描述 = 列表项的ID此操作使用。 / > ;
< / Parameters >
< / Action >
< / Actions >
< / WorkflowInfo >

解决方案

你复制的代码显然缺少部分类的其他部分。部分类在多个文件中实现,我猜你没有另一个AttachDocToItem.Designer.cs文件。



在这种情况下,你有两个选择:



1.从中删除InitializeComponent调用构造函数,还从类定义中删除partial关键字。离开它仍然可能编译,但它不是很好的做法。



2.创建一个新的活动(添加 - >新项目,选择活动并创建一个新的一)。将其命名为类似的东西,然后将上面的代码复制到其中,然后在删除此文件后重命名该文件。这将为您创建分部类的另一面。



3.创建一个名为AttachDocToItem.Designer.cs的新文件。添加类定义以及您需要的内容。您可以通过创建新的Activity并查看designer.cs文件所包含的内容来了解​​您的需求。但不建议这样做,因为为了正确实现它,您需要编辑csproj文件并将.designer文件作为依赖项添加到主文件中。这需要大量的工作。



就个人而言,我会做#2的方法。然后写一封严厉的电子邮件给你得到代码的人告诉他不完整。


I have this code but when I run the project. Error 2 The name 'InitializeComponent' does not exist in the current context. Can someone help me implement InitializeComponent (); pleas source
http://aroundsharepoint.blogspot.mx/2011/01/workflow-action-attach-document-to.html[^]

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Linq;
using System.IO;
using Microsoft.SharePoint;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using Microsoft.SharePoint.WorkflowActions;


namespace AttachDocToItemProject
{
    public partial class AttachDocToItem : Activity
    {

        public static DependencyProperty LibIdProperty = DependencyProperty.Register("LibId", typeof(string), typeof(AttachDocToItem));
        public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(AttachDocToItem));
        public static DependencyProperty DocItemProperty = DependencyProperty.Register("DocItem", typeof(Int32), typeof(AttachDocToItem));
        public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(Int32), typeof(AttachDocToItem));
        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(AttachDocToItem));

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [Description("ID of the document library storing the doc that will be attached to the item")]
        public string LibId
        {
            get { return ((string)(base.GetValue(AttachDocToItem.LibIdProperty))); }
            set { base.SetValue(AttachDocToItem.LibIdProperty, value); }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [Description("ID of the list keeping the item to which the document will be attached to")]
        public string ListId
        {
            get { return ((string)(base.GetValue(AttachDocToItem.ListIdProperty))); }
            set { base.SetValue(AttachDocToItem.ListIdProperty, value); }
        }

        [Description("ID of the list item to which the document will be attached to")]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public Int32 ListItem
        {
            get { return ((Int32)(base.GetValue(AttachDocToItem.ListItemProperty))); }
            set { base.SetValue(AttachDocToItem.ListItemProperty, value); }
        }

        [Description("ID of the document item to which the document will be attached to")]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public Int32 DocItem
        {
            get { return ((Int32)(base.GetValue(AttachDocToItem.DocItemProperty))); }
            set { base.SetValue(AttachDocToItem.DocItemProperty, value); }
        }

        [Description("Context")]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public WorkflowContext __Context
        {
            get { return ((WorkflowContext)(base.GetValue(__ContextProperty))); }
            set { base.SetValue(__ContextProperty, value); }
        }


        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {

                __Context.Web.AllowUnsafeUpdates = true;

                Guid id = new Guid(ListId);
                SPList list = __Context.Web.Lists[id];
                Guid did = new Guid(LibId);
                SPList docLib = __Context.Web.Lists[did];
                SPListItem sourceItem = docLib.GetItemById(DocItem);
                SPFile sourceDoc = sourceItem.File;
                byte[] fichierbyte = sourceDoc.OpenBinary();

                SPListItem destinationItem = list.GetItemById(ListItem);
                destinationItem.Attachments.Add(sourceItem.Name, fichierbyte);
                destinationItem.Update();
                return ActivityExecutionStatus.Closed;

            }
            catch (Exception Ex)
            {

                return ActivityExecutionStatus.Faulting;
                throw new Exception(Ex.Message + "&&&&" + Ex.StackTrace);

            }
            finally
            {

            }
            return ActivityExecutionStatus.Closed;
        }

        public AttachDocToItem()
        {
            InitializeComponent();
        }
       
    }
}


<?xml version="1.0" encoding="utf-8"?>

<WorkflowInfo>
  <Actions Sequential="then" Parallel="and">
    <Action Name="Attach Doc to Item"

           ClassName="AttachDocToItem"

           Assembly="AttachDocToItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f4f4b70dd2f12d2"

           AppliesTo="all" Category="New">
      <RuleDesigner Sentence="Attach %1 to %2">
        <FieldBind Text="this document" Field="LibId,DocItem" DesignerType="ChooseDoclibItem" Id="1" />
        <FieldBind Text="this item" Field="ListId,ListItem" DesignerType="ChooseListItem" Id="2"/>
      </RuleDesigner>
      <Parameters>
        <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" />
        <Parameter Name="LibId" Type="System.String, mscorlib" Direction="In" InitialBinding="__list"/>
        <Parameter Name="DocItem" Type="System.Int32, mscorlib" Direction="In" InitialBinding="__item" DesignerType="ListItem"  Description="ID of the list item used by this action." />
        <Parameter Name="ListId" Type="System.String, mscorlib" Direction="In"/>
        <Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In"  DesignerType="ListItem"  Description="ID of the list item used by this action." />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>

解决方案

The code you copied from is obviously missing the other part of the "partial" class. Partial classes are implemented in multiple files, I'm guessing you don't have another AttachDocToItem.Designer.cs file.

In that case, you have a couple options:

1. Remove the InitializeComponent call from the constructor, and also remove the partial keyword from the class definition. Leaving it there will still probably compile, but its not good practice.

2. Create a new Activity (Add->New Item, select Activity and make a new one). Name it something similar and then copy the code above into it, then rename the file after you delete this one. This will create the other side of the partial class for you.

3. Create a new file called AttachDocToItem.Designer.cs. Add the class definition and what you need to it. You can find out what you need by creating a new Activity and seeing what the designer.cs file holds. This isn't recommended though since in order to implement it properly you'll need to edit the csproj file and add the .designer file as a dependency to the main file. This requires a lot of work.

Personally I'd do the #2 approach. Then write a stern email to the guy you got the code from telling him its incomplete.


这篇关于在Visual Studio中创建Sharepoint设计器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆