承接MOSS各种工作流开发 联系人:王先生.电话:13691349686QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

2011年3月21日 #

CAML 多表查询 SPQuery.Joins and ProjectedFields

      在实际的SharePoint项目中,业务都比较复杂,其实我们的List一直都支持多表查询的~~

 

嘿嘿!

Demo:

字典表:

CityState表:  标题(Text)   State(Text)  AreaCode(num)

Locations表:  标题(Text)   City (Text)  zipCode (num)

Customer表:  CustomerName(Text) Address(Text) City(Lookup) State(Lookup)

 

下面通过SPQuery 进行多表查询(不过Joins 和ProjectedFields 对于字段有很多限制,join的表不支持多行文本,不支持用户或用户组 )

        using (SPSite site = new SPSite(@"http://localhost/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list1 = web.Lists["Customers"];
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>AA</Value></Eq></Where>";
                    query.Joins = @"<Join Type='LEFT' ListAlias='Locations'><Eq><FieldRef Name='City' RefType='ID'/><FieldRef List='Locations' Name='ID'/></Eq></Join><Join Type='LEFT' ListAlias='CityState'><Eq><FieldRef Name='State' RefType='ID'/><FieldRef List='CityState' Name='ID'/></Eq></Join>";//
                    query.ProjectedFields = @"<Field Name='zipCode1' Type='Lookup' List='Locations' ShowField='zipCode'/><Field Name='AreaCode' Type='Lookup' List='CityState' ShowField='AreaCode'/><Field Name='CreateU' Type='Lookup' List='CityState' ShowField='Created'/>";
                    query.ViewFields = @"<FieldRef Name='Title'/><FieldRef Name='City'/><FieldRef Name='zipCode1'/><FieldRef Name='State'/><FieldRef Name='AreaCode'/><FieldRef Name='CreateU'/>";//
                    SPListItemCollection items = list1.GetItems(query);
                }
            }

Joins对应的join的表,ProjectedFields 对应的Join的表的字段

ViewFields 对应的需要显示的字段。。。

 

 

稍等继续......

 

 

 

 


 

posted @ 2011-03-21 21:58 A A 阅读(376) 评论(1) 编辑

2011年1月22日 #

SharePoint 2010 你状态机了吗!

     由于要给客户做培训,关于sharepoint 2010 工作流的,打算在网上找个demo看看的,结果这方面的demo 还比较少,只能自己折腾了

哎,谁叫客户就是上帝嘛。 开始打算用顺序流的,发现网上这方面的资料比较多,而且顺序流不能体现实际的业务,看起来太“土”。。。。

状态机流程图

首先申请人---〉操作员审批----领导审批---结束

当然还有拒绝的动作,我就不在这里说明了,大家看图·

申请表单

审批表单

流程结束

 

设计这个流程的时候,发现和2007的版本一样,在基于VS这块,无论顺序还是状态流程,貌似变化不大@

开发sharepoint 2010 工作流 需要注意这个配置xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Workflow
     Name="AA.Workflows.State - StateMachine"
     Description="My SharePoint Workflow"
     Id="630ffa3d-6da8-4e77-a77c-c602e49f956d"
     CodeBesideClass="AA.Workflows.State.StateMachine.StateMachine"
     CodeBesideAssembly="$assemblyname$"
     AssociationUrl="_layouts/AA.Workflows.State/StateMachine/WorkflowAssociationForm1.aspx"
     InstantiationUrl="_layouts/AA.Workflows.State/StateMachine/WorkflowInitiationForm1.aspx"
     TaskListContentTypeId="0x010801005e7969df923b4d7190ee6dcdae487a57">
   
    <Categories/>
    <MetaData>
      <AssociationCategories>List</AssociationCategories>
      <!-- Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have -->
      <!--<Association_FormURN>[URN FOR ASSOCIATION FORM]</Association_FormURN>
       <Instantiation_FormURN>[URN FOR INSTANTIATION FORM]</Instantiation_FormURN>
      <Task0_FormURN>[URN FOR TASK (type 0) FORM]</Task0_FormURN>
      <Task1_FormURN>[URN FOR TASK (type 1) FORM]</Task1_FormURN>-->
      <!-- Modification forms: create a unique guid for each modification form -->
      <!--<Modification_[UNIQUE GUID]_FormURN>[URN FOR MODIFICATION FORM]</Modification_[UNIQUE GUID]_FormURN>
      <Modification_[UNIQUE GUID]_Name>[NAME OF MODIFICATION TO BE DISPLAYED AS A LINK ON WORKFLOW STATUS PAGE</Modification_[UNIQUE GUID]_Name>
      -->
      <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
     
    </MetaData>
  
  </Workflow>
  <ContentType ID="0x010801005e7969df923b4d7190ee6dcdae487a57"
              Name="AA.Workflows.State - ContentType2"
              Group="Custom Content Types"
              Description="My Content Type"
              Version="0">
    <FieldRefs>
      <FieldRef ID="{F2C72B83-CA8A-45EE-9F72-3286F6E37E12}"  Name="TaskData" DisplayName ="Task Data"/>
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <Edit>_layouts/AA.Workflows.State/TaskApprove.aspx</Edit>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>

 

尤其是这个内容ID

后台aspx页面像Workflow传送value的时候可以通过

 Hashtable htData = new Hashtable();
                htData["TaskData"] = "true";

这个hashtable来做

SPWorkflowTask.AlterTask(this.taskItem, htData, true);

可以把value传送给工作流

在流程里面取值:

在审批动作里面直接这样取

   private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
        {


            this.IsOperatorPenson = bool.Parse(this.afterProperties1.ExtendedProperties["TaskData"].ToString());
            this.leaderPenson = this.afterProperties1.ExtendedProperties["ApproveUser"].ToString();
            this.auditComments = this.afterProperties1.ExtendedProperties["Comments"].ToString();
        }

 

需要代码学习的,可以留下邮箱,我稍后也会把代码上传的

困。。。

 

posted @ 2011-01-22 00:01 A A 阅读(595) 评论(7) 编辑

2011年1月11日 #

SharePoint 文档库打开HTML 直接浏览而不是打开下载对话框

SharePoint  文档库打开HTML 直接浏览而不是打开下载对话框

在实际的项目中,可能有些时候需要把一些html放在文档库中,而不是直接提示下载

 

这个需要在管理中做一个简单的配置:

管理中心-〉应用程序管理-〉管理web应用程序-〉选择站点-〉常规设置-》浏览器文件处理程序,改成许可

posted @ 2011-01-11 16:20 A A 阅读(348) 评论(0) 编辑

2011年1月6日 #

SharePoint Write Logs

using System;
using System.Security.Permissions;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace AnnouncementListEvent.EventReceiver1
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class EventReceiver1 : SPItemEventReceiver
    {
       /// <summary>
       /// An item is being added.
       /// </summary>
       public override void ItemAdding(SPItemEventProperties properties)
       {
           base.ItemAdding(properties);
           writeDataToLogFile(properties, "ItemAdding Event");
           writeListItemToCustomList(properties, "ItemAdding Event");
       }

       private void writeListItemToCustomList(SPItemEventProperties properties, string eventName)
       {
           string spLog = "";
           DateTime currentTime = DateTime.Now;
           spLog = eventName + " " + currentTime.ToString();

           using (SPSite site = new SPSite("http://moss2010/"))
           {
               using (SPWeb web = site.OpenWeb())
               {
                   web.AllowUnsafeUpdates = true;
                   SPList list = web.Lists["Log"];
                   SPListItem Item = list.Items.Add();
                   Item["Title"] = properties.ListTitle.ToString();
                   Item["Log Entry"] = spLog;
                   Item.Update();
               }
           }

       }

       private void writeDataToLogFile(SPItemEventProperties properties, string eventName)
       {
           FileIOPermission myPermissions = new FileIOPermission(PermissionState.Unrestricted);
           myPermissions.AddPathList(FileIOPermissionAccess.AllAccess, "c:\\Authoring");

           StreamWriter sw = File.AppendText(@"C:\Authoring\mySPLog.txt");
           StringBuilder sb = new StringBuilder();
           sb.AppendFormat("Date, Event and List:\n {0} {1} {2} ", DateTime.Now.ToString(), eventName, properties.ListTitle);
           sw.WriteLine(sb.ToString());
           sw.Close();
       }

    }
}

posted @ 2011-01-06 21:59 A A 阅读(44) 评论(0) 编辑

2011年1月5日 #

User Profile Data Web Part 读取属性字段

User Profile Data Web Part

User Profile Data Web Part Web 部件菜单
 
Property Name Display Name
UserProfile_GUID Id
SID SID
ADGuid Active Directory ID
AccountName 帐户名
FirstName 名字
SPS-PhoneticFirstName 拼音名
LastName 姓氏
SPS-PhoneticLastName 拼音姓
PreferredName 名称
SPS-PhoneticDisplayName 拼音显示姓名
WorkPhone 单位电话
Department 部门
Title 职务
SPS-JobTitle 职务
Manager 经理
AboutMe 描述
PersonalSpace 个人网站
PictureURL 图片
UserName 用户名
QuickLinks 快速链接
WebSite 网站
PublicSiteRedirect 公共网站重定向
SPS-DataSource 数据源
SPS-MemberOf 隶属于
SPS-Dotted-line 非直属经理
SPS-Peers 同级
SPS-Responsibility 专业领域
SPS-SipAddress SIP 地址
SPS-MySiteUpgrade 我的网站升级
SPS-DontSuggestList “不建议”列表
SPS-ProxyAddresses 代理服务器地址
SPS-HireDate 雇用日期
SPS-DisplayOrder 显示顺序
SPS-ClaimID 声明用户标识符
SPS-ClaimProviderID 声明提供程序标识符
SPS-ClaimProviderType 声明提供程序类型
SPS-LastColleagueAdded 上一个添加的同事
SPS-OWAUrl Outlook Web Access URL
SPS-SavedAccountName 保存的帐户名称
SPS-SavedSID 保存的 SID
SPS-ResourceSID 资源林 SID
SPS-ResourceAccountName 资源林帐户名
SPS-ObjectExists 对象已存在
SPS-MasterAccountName 主帐户名
SPS-DistinguishedName 可分辨名称
SPS-SourceObjectDN 源对象可分辨名称
SPS-LastKeywordAdded 最新添加的关键字
WorkEmail 工作电子邮件
CellPhone 移动电话
Fax 传真
HomePhone 住宅电话
Office 办公室
SPS-Location 办公地点
SPS-TimeZone 时区
Assistant 助手
SPS-PastProjects 过去参与的项目
SPS-Skills 技能
SPS-School 学校
SPS-Birthday 生日
SPS-StatusNotes 状态消息
SPS-Interests 兴趣
SPS-EmailOptin 电子邮件通知

Code

 

 using (SPSite site = new SPSite("http://moss2010/"))
            {
                SPServiceContext context =
                    SPServiceContext.GetContext(site);
                UserProfileManager m_mngr = new UserProfileManager(context);

                //Get the properties
                PropertyCollection props = m_mngr.Properties;

                //Create a Dictionary to store property data.
                Dictionary<string, string> UserProps = new Dictionary<string, string>();

                foreach (Property prop in props)
                {
                    UserProps.Add(prop.Name, prop.DisplayName);
                }
                //Bind the Dictionary to a GridView control.
                GridView1.DataSource = UserProps;
                GridView1.Columns[0].HeaderText = "Property Name";
                GridView1.Columns[1].HeaderText = "Display Name";
                GridView1.DataBind();

            }

 

posted @ 2011-01-05 23:22 A A 阅读(252) 评论(0) 编辑

ECMAScript Client OM(传说中的js客户端编程)

把这个aspx文件放在_layouts下面,直接通过js访问后台文件

 

 

<%@ Page Language="C#" %>
<%@ Register Tagprefix="SharePoint"
    Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>ECMAScript Client OM</title>
      <script type="text/javascript">


          function CallClientOM() {
              var context = new SP.ClientContext.get_current();
              this.website = context.get_web();
       this.listCollection = website.get_lists();

              context.load(this.listCollection, 'Include(Title, Id)');
              context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
          }


          function onQuerySucceeded(sender, args) {

   var listInfo = '';

   var listEnumerator = listCollection.getEnumerator();

          while (listEnumerator.moveNext())
          {
              var list = listEnumerator.get_current();
              listInfo += 'List Title: ' + list.get_title() + ' ID: ' + list.get_id() + '\n';
          }
    alert(listInfo);

          }

          function onQueryFailed(sender, args) {
              alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
          }

      </script>       
  </head>
  <body>
    <form id="form1" runat="server">
      <SharePoint:ScriptLink ID="ScriptLink1" Name="sp.debug.js" LoadAfterUI="true" Localizable="false" runat="server" />
 
<a href="#" onclick="CallClientOM()">Click here to Execute</a>

      <SharePoint:FormDigest runat="server" />
    </form>
  </body>
</html>

 

posted @ 2011-01-05 22:57 A A 阅读(235) 评论(0) 编辑

2011年1月3日 #

自定义个性化 EditPeople控件

摘要: 最近折腾SharePoint 2010 比较多,有些客户想定制EditPeople控件,有些领导感觉那个搜索不太“好”,希望能有一个树形选择就完美了哎,客户有要求,咱们哪里能不办? 图1 图2图3代码 :<script type="text/javascript" language="javascript"> /* * Validate User name */ function fetchUserName() { var buttonClientID = '<%=imgButtonCheckNames.ClientID%>'; var htmlButton = document.getEle阅读全文

posted @ 2011-01-03 15:35 A A 阅读(281) 评论(2) 编辑

2010年12月26日 #

使用SharePoint Management PowerShell来完成对SharePoint的操作

摘要: 用户可以使用SharePoint Management PowerShell来完成对SharePoint的操作了。  这里我们以site的Import和Export作例子,来简单介绍怎么用PowerShell完成上述操作。我们知道,我们在对Site作backup和restore时,有2种选择,一种是直接用Backup,restore命令,这样是对整个site collection作备份还原操作,然而当我们只是备份还原某个site或者是某个list的时候,Import和Export成了我们的选择。  首先将源site 作export,在PowerShell窗口输入以下是代码片段:Export-S阅读全文

posted @ 2010-12-26 18:11 A A 阅读(189) 评论(0) 编辑

2010年11月30日 #

Developer Dashboard 排忧解难!!!

摘要: 描述:   今天在客户现场遇到一个怪异的问题,SharePoint 2010 首页突然访问奇慢无比呀(其他站点正常),可是昨天晚上还是好好的嘛,今天又要给领导汇报,给我急得啊,愁死我了。。感觉是那个webpart 出问题了,可是以前都是好好的呀,初步排查应该是首页那个webpart的访问数据有问题,导致的情况,首页无非是,内容查询 ,内容编辑 EXCEL相关webpart 为了搞清楚 具体是那个w...阅读全文

posted @ 2010-11-30 21:21 A A 阅读(220) 评论(0) 编辑

2010年11月10日 #

使用SharePoint 人员选择控件 在 WEB APP开发

摘要: 首先 引用名字空间呗<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>然后在页面...阅读全文

posted @ 2010-11-10 15:36 A A 阅读(281) 评论(0) 编辑