海外网站哪个最好,可以免费打广告的网站,兼职设计师平台,实事新闻热点webpart我们就不详细阐述了#xff0c;在APP的开发中#xff0c;自定义属性设置可以通过APP webpart的URL查询字符串传递#xff0c;它通过IFRAME来显示远程的内容。废话不多说#xff0c;我们开始实际操作。
打开Visual Studio#xff0c;新建SharePoint应用程序项目在APP的开发中自定义属性设置可以通过APP webpart的URL查询字符串传递它通过IFRAME来显示远程的内容。废话不多说我们开始实际操作。
打开Visual Studio新建SharePoint应用程序项目名字我们就叫做SharePointAppPartTest。 参照上一篇完成项目的创建。 右键点击SharePoint项目节点选择添加-新建项选择客户端Web部件宿主Web起名叫做ClientWebPartTest点击确定并在下一个对话框中保留默认完成添加。 我们可以看到解决方案中是如下图生成的 SharePoint工程中有一个Elements.xml元素用来说明我们创建的webpart托管Web应用程序中的Pages文件夹下生成了一个对应的ASPX页面。打开Elements.xml文件可以看到如下默认生成的内容
ClientWebPart NameClientWebPartTest TitleClientWebPartTest 标题 DescriptionClientWebPartTest 说明 DefaultWidth300 DefaultHeight200!-- Content 元素标识将在客户端 Web 部件内呈现的页面的位置在查询字符串上使用模式 _propertyName_ 引用了属性示例: Src~appWebUrl/Pages/ClientWebPart1.aspx?Property1_property1_ --Content Typehtml Src~remoteAppUrl/Pages/ClientWebPartTest.aspx?{StandardTokens} /!-- 在 Properties 元素中定义属性。请记得在上述 Content 元素的 Src 特性上放置属性名称。 --Properties/Properties/ClientWebPart
我们来添加几个属性在Properties节点下声明如下四个属性string、int、bool、enum
PropertyNamemyStrPropTypestringRequiresDesignerPermissiontrueDefaultValueString default valueWebCategoryMy Test AppsWebDisplayNameA property of type string./PropertyPropertyNamemyIntPropTypeintRequiresDesignerPermissiontrueDefaultValue0WebCategoryMy Test AppsWebDisplayNameA property of type integer./PropertyPropertyNamemyBoolPropTypebooleanRequiresDesignerPermissiontrueDefaultValuefalseWebCategoryMy Test AppsWebDisplayNameA property of type boolean./PropertyPropertyNamemyEnumPropTypeenumRequiresDesignerPermissiontrueDefaultValue1stWebCategoryMy Test AppsWebDisplayNameA property of type enum.EnumItemsEnumItem WebDisplayNameFirst option Value1st/EnumItem WebDisplayNameSecond option Value2nd/EnumItem WebDisplayNameThird option Value3rd//EnumItems/Property
都是我们测试中用的所以名称有些随意实际应用中请取有意义的名称。 属性创建完之后如何与webpart进行关联呢我们需要修改Content节点的Src属性修改后的节点如下所示 Content Typehtml Src~remoteAppUrl/Pages/ClientWebPartTest.aspx?{StandardTokens}StrProp_myStrProp_IntProp_myIntProp_BoolProp_myBoolProp_EnumProp_myEnumProp_Editmode_editMode_ /
借助这种方式APP webpart的参数通过URL的查询字符串传递到ASPX页面接下来我们到ASPX页面去处理我们定义的参数。
打开ClientWebPartTest.aspx页面在空的DIV元素内加入如下控件
asp:Label IDLabel1 runatserver/asp:Label
asp:Literal IDLiteral1 runatserver TextHello world from an app part/asp:Literal
打开后台代码ClientWebPartTest.aspx.cs在Page_Load方法中加入如下代码来获取传递的参数
var intParam Request.QueryString[IntProp];var strParam Request.QueryString[StrProp];var boolParam Request.QueryString[BoolProp];var enumParam Request.QueryString[EnumProp];var editMode Request.QueryString[EditMode];if (true editMode){Literal1.Text The App Part is in edit mode;}else{Literal1.Text myIntProp intParam br myStrProp strParam br myBoolProp boolParam br myEnumProp enumParam;}
var spContext SharePointContextProvider.Current.GetSharePointContext(Context);using (var clientContext spContext.CreateUserClientContextForSPHost()){clientContext.Load(clientContext.Web, web web.Title);clientContext.ExecuteQuery();this.Label1.Text Site Title: clientContext.Web.Title br;}
代码中我又加了一段之前的CSOM是想用简单的组合来告诉大家我们其实可以在其中做很多的事情。
F5生成并部署APP成功之后弹出浏览器窗体 一样的东西默认会跳转到应用程序的Default页面我们回到我们的开发人员网站点击右上角的设置-编辑网页选择插入选项卡点击应用程序部件。 点击添加按钮完成页面中添加webpart的操作。
好了webpart中已经显示了我们让它显示的内容。 我们回到编辑状态编辑这个webpart可以看到我们添加的自定义属性。我们对属性进行适当的修改并保存。 以上就是开发APP webpart的大致过程。
另外一点需要说明的是由于我们在调试状态下并没有发布APP所以需要Visual Studio处于调试状态下才可以进行访问测试。