何小碩's profileGet More... ExperiencePhotosBlogListsMore Tools Help

Blog


    February 28

    感謝大家的支持哦 ^o^

    這一個 部落格 開始成立到現在短短四個月的時間已經有三千多人到訪 呵呵 真的挺令人驚訝的, 也希望網友朋友們在未來能多多支持嚕~~ 我會不定時的去分享專案過程中所遇到的相關問題與其他網友或 MVP 部落格中我覺得不錯以後會用到的文章 那也希望網友們如果有問題可以用 MSN 來一起討論吧~~

    MSN: hilfiger1014@hotmail.com

    MOSS 2007 資料庫容量控管機制 Add-In Beta Release

     MOSS 2007 資料庫容量控管機制與優點

     

    • 原始網站資料庫不再日益膨脹變大
    • 移轉過程中可同時作稽核控管
    • 使用者搜尋的同時可搜尋相關資料不會因為移轉而查詢不到
    • 所有管控機制均由中央管理中心進行控管不需額外加裝 Client 管理工具
    • 可單獨針對單一網站進行管理由使用者確認是否此網站要開啟此功能
    • 安裝簡易第一次安裝結束即立即啟動此服務管理人員僅只需選擇要啟動安裝的網站與全數安裝
    • Add-In 工具完全符合 MOSS 2007 開發原則與使用原則與 MOSS 2007 相容

    MOSS 後端資料庫容量控管示意圖

    February 20

    Workflow: An error has occured in Approval

    I have created a custom approval workflow in a document library. On customize workflow screen I selected the following option:

    [x] Update the approval status (use this workflow to control content approval)
    During workflow testing I was surprised when SharePoint reported the following error:
    An error has occured in Approval.“

    The solution for this problem is very simple, if you want your workflow to update approval status you need to enable content approval in your document library. To enable content approval here is what you need to do: Go to your document library Settings > Versioning Settings and select „Yes” for “Require content approval for submitted items?“ option.

    Add Expression boxes to show workflow status

    Though you could now add the field returned from the SharePoint data connection to the form view, it would not mean much to users because SharePoint returns values to represent workflow status, not the status you see in the browser. The following table lists the values and what they mean.
    Workflow value Status
    0 Not Started
    1 Failed On Start
    2 In Progress
    3 Error Occurred
    4 Stopped By User
    5 Completed
    15 Canceled
      Note
    To confirm a value and its associated Status, add the workflow field to the form template view, change the workflow status of a form in the form library or in InfoPath, then close and re-open it in InfoPath. The workflow value will appear in the control bound to the workflow field.
    Use the following procedure to add expression boxes to the form for each of these values, and conditionally hide each expression box based on the workflow field returned in the data connection.
    1. Type "Workflow Status:" where you want to show the workflow status in the view.
    2. Place an Expression Box control from the Controls task pane to the right of the text.
    3. In the Insert Expression Box dialog box, type "Not Started" with quotations, and click OK.
    4. Double-click the expression box, and click the Conditional Formatting button on the Display tab.
    5. On the Conditional Formatting dialog box,click the Add button .
    6. In the If this condition is true section, click the first drop-down box, and click Select a field or group.
    7. In the Select a field or group dialog box, change the data source to the SharePoint data connection.
    8. Click to expand the field list until you see the workflow status field, which is the name of the workflow, and click OK.
    9. In the Conditional Formatting dialog box, click the second drop-down box and select is not equal to.
    10. In the third drop-down box, select Type a number and enter the value of 0 (zero).
    11. Click the And button to add a second condition.
    12. Repeat steps six through eight to select the workflow status field.
    13. In the second drop-down box select is present.
    14. Check the Hide this control box and click OK three times to dismiss all dialog boxes.

    Repeat the steps above, adding a new Expression Box control for each workflow status in the table. You can add and resize the expression boxes so they are next to each other or even slightly overlapping. Because only one status will be displayed at a time, they will always appear next to the "Workflow Status:" text.

      Note
    Two conditions are also necessary for the other values in the table. The first condition is if the workflow status field is not equal to the workflow value corresponding to the status you entered in quotations in the expression box, then hide the control. The second condition is if the workflow status field is not present, then hide the control. These conditions are separated with an or instead of the default and when you click the And button to add a second condition.

    Once you are finished with adding the expression boxes, save and re-publish the form template to the SharePoint library with the same options as before. Once the form is republished, existing forms will contain the proper workflow status in the form.

    Troubleshooting - Publishing

     

    KB 大彙整

    http://support.microsoft.com/default.aspx/kb/946517

    FIX: You may be unable to manage IIS 6.0 by using Server Manager if two threads access IIS 6.0 at the same time.

    http://support.microsoft.com/default.aspx/kb/832809

    Icons are not displayed for Adobe PDF documents that are listed in the search results when you search your portal site in SharePoint Portal Server 2003 or in SharePoint Server 2007

    http://support.microsoft.com/kb/939313

    Error message when you try to open a help window from a SharePoint Server 2007 site or from a Windows SharePoint Services 3.0 site: "Cannot display help"

    http://support.microsoft.com/kb/938219

    Error message when content is crawled in SharePoint Server 2007: "An unrecognized HTTP status was received. Check that the address can be accessed using Internet Explorer"

    http://support.microsoft.com/kb/937884

    How to index SharePoint Portal Server 2003 list items in SharePoint Server 2007

    http://support.microsoft.com/kb/936909

    Icons that represent 2007 Office files are incorrect, and the "Edit in Microsoft Office <ProgramName>" option does not appear in a document library in SharePoint Portal Server 2003 or in Windows SharePoint Services 2.0

    http://support.microsoft.com/kb/936861

    The sort order of the selected view is incorrect when you insert a hyperlink into a document in a document library in SharePoint Server 2007

    http://support.microsoft.com/kb/936623

    Error message after you change the configuration database name when you perform a gradual upgrade from SharePoint Portal Server 2003 to SharePoint Server 2007: "An update conflict has occurred"

    http://support.microsoft.com/kb/935502

    Error message when you configure the Content Query Web Part in SharePoint Server 2007: "The query cannot be completed because the number of lists in the query exceeded the allowable limit"

    http://support.microsoft.com/kb/934793

    Description of the SharePoint Server 2007 hotfix package: April 12, 2007

    http://support.microsoft.com/kb/935502

    Error message when you configure the Content Query Web Part in SharePoint Server 2007: "The query cannot be completed because the number of lists in the query exceeded the allowable limit"

    http://support.microsoft.com/kb/933560

    The Windows Server 2003 /3GB switch is not supported in Windows SharePoint Services 2.0 or in later versions or in SharePoint Portal Server 2003 SP2 or in later versions

    http://support.microsoft.com/kb/932816

    FIX: You experience various problems in Windows Workflow Foundation

    http://support.microsoft.com/kb/932744

    Information about the Maintenance Plan Wizard in SQL Server 2005 and about tasks that administrators can perform against SharePoint databases

    http://support.microsoft.com/kb/932743

    Some items are not indexed correctly when you configure SharePoint Portal Server 2003 to crawl content that resides on a Windows SharePoint Services 3.0 site or on a SharePoint Server 2007 site

    http://support.microsoft.com/kb/932742

    Error message when you try to access a custom application that includes ASP.NET resource files in Windows SharePoint Services 3.0 or in SharePoint Server 2007: "Resource file not found"

    http://support.microsoft.com/kb/932741

    RSS feeds are not updated as expected when you configure them for content in a Windows SharePoint Services 3.0 Web site by using an RSS reader

    http://support.microsoft.com/kb/932091

    Opis aktualizacji dla programu Windows SharePoint Services 3.0: 27 marca 2007

    http://support.microsoft.com/kb/930887

    You experience issues with portal alerts in SharePoint Portal Server 2003 or with search performance in SharePoint Server 2007 after you create SQL Server 2005 maintenance plans

    http://support.microsoft.com/kb/930147

    Mobile browsers and devices that are supported in Windows SharePoint Services 3.0 and in SharePoint Server 2007

    http://support.microsoft.com/kb/930007

    Description of the supported method to upgrade from MCMS 2002 to SharePoint Server 2007

    http://support.microsoft.com/kb/929649

    How to use SQL Server to take a snapshot of a Windows SharePoint Services 3.0 content database

    http://support.microsoft.com/kb/929360

    You cannot create a new document or check out an existing document in a Windows SharePoint Services 3.0 document library when you have multiple versions of Office installed

    http://support.microsoft.com/kb/929260

    You cannot use the "Minimize" option and other menu options in Web Parts in the personal view on a Windows SharePoint Services site

    http://support.microsoft.com/kb/928747

    The "View in Web Browser" option does not appear as expected when you try to view an Excel workbook in SharePoint 2007

    http://support.microsoft.com/kb/928746

    Error message when you try to open an Excel workbook in SharePoint Server 2007: "Could not establish trust relationship for the SSL/TLS secure channel"

    http://support.microsoft.com/kb/928742

    You cannot load an Excel 2007 workbook in Excel Web Access when a SharePoint Server 2007 Web site uses Basic authentication and when the trusted file location type is set to HTTP

    http://support.microsoft.com/kb/928741

    A maximum number of 25 sessions can be active at the same time on Excel Services when you enable anonymous access to a SharePoint Server 2007 Web site

    http://support.microsoft.com/kb/928738

    How to configure the Excel Services Unattended Service account in Microsoft Office SharePoint Server 2007

    http://support.microsoft.com/kb/928728

    You receive an error message when you use Excel Web Access to refresh the data connections for an Excel 2007 workbook

    http://support.microsoft.com/kb/928727

    Description of the Analysis Services formats that are supported by cube formulas in Excel Services in SharePoint Server 2007

    http://support.microsoft.com/kb/928626

    The Web front-end server that is running Excel Services in SharePoint Server 2007 encounters a System.Threading.ThreadAbortException exception

    http://support.microsoft.com/kb/928620

    Error message when you try to start the Search service in SharePoint 2007: "An unhandled exception occurred in the user interface"

    http://support.microsoft.com/kb/928619

    Adobe Reader files cannot be found after you add the .pdf file type to the list of crawled file types in SharePoint Server 2007

    http://support.microsoft.com/kb/928617

    Error message when you try to create a site collection by using a site template in the top-level site template gallery in Windows SharePoint Services 3.0: "The template you have selected is invalid or cannot be found"

    http://support.microsoft.com/kb/928304

    You cannot select a new index server on the "Edit Shared Services Provider" page in SharePoint Server 2007

    http://support.microsoft.com/kb/928303

    Error message when you try to view a Web page to which you added a Content By Query Web part in SharePoint Server 2007: "404 File Not Found"

    http://support.microsoft.com/kb/928302

    Anonymous users can search the version comments in a document or in a picture in SharePoint Server 2007

    http://support.microsoft.com/kb/928037

    Error message when you try to create a document template in SharePoint Server 2007: "To save to the server, correct the invalid or missing required properties"

    http://support.microsoft.com/kb/928036

    Users still have the Contributor permission on a released task in a SharePoint Server 2007 document library

    http://support.microsoft.com/kb/928034

    The Document ID log report does not contain information about deleted documents in SharePoint Server 2007

    http://support.microsoft.com/kb/928033

    Error message in SharePoint Server 2007 when you log on to the Windows SharePoint Services 3.0 document library and then click "My Approval": "Unexpected query execution failure, error code 1205"

    http://support.microsoft.com/kb/928032

    The Document ID log report view may stop responding when you view a Document ID log report that contains lots of groups in SharePoint Server 2007

    http://support.microsoft.com/kb/928031

    Review form buttons are disabled after an assigned role member clicks "Claim Task" and then clicks the Approve button in SharePoint Server 2007

    http://support.microsoft.com/kb/928030

    When you insert a label in a document that you have created and then saved in a SharePoint Server 2007 document library, some characters do not appear in the Label field

    http://support.microsoft.com/kb/928029

    Document library does not open successfully when you try to use Internet Explorer 7 to open a SharePoint Server 2007 or a Windows SharePoint Services 3.0 document library

    http://support.microsoft.com/kb/928028

    Error message when a user tries to save an item to a list or respond to a survey in a Windows SharePoint Services 3.0 Web site: "An unexpected error has occurred"

    http://support.microsoft.com/kb/927919

    You cannot search a Windows SharePoint Services 3.0 site when the host header site uses HTTP and HTTPS

    http://support.microsoft.com/kb/927675

    No Adobe PDF documents are returned in the search results when you search a Windows SharePoint Services 3.0 Web site

    http://support.microsoft.com/kb/927012

    Error message when you perform a search query after you upgrade to the release version of Microsoft Windows SharePoint Services 3.0: "Your search cannot be completed because of a service error"

    http://support.microsoft.com/kb/926961

    Error message when you use SharePoint 3.0 Central Administration to try to re-add a content database in Windows SharePoint Services 3.0

    http://support.microsoft.com/kb/926959

    Error when you try to edit the content source schedule in Microsoft Office SharePoint Server 2007: "Access is denied"

    http://support.microsoft.com/kb/926958

    Error message when you use Internet Explorer 7 to open a Word document in a Windows SharePoint Services 3.0 document library: "The AppShow command is not available

    because permission for this document is currently restricted"

    http://support.microsoft.com/kb/926719

    A Column list in a content type template is not updated on a Windows SharePoint Services 3.0 child site

    http://support.microsoft.com/kb/926370

    The status of a workflow appears as "Failed to Start" when you try to start a workflow from a survey response in Windows SharePoint Services 3.0

    http://support.microsoft.com/kb/926321

    Error message when you try to restore a Windows SharePoint Services 3.0 site collection by using a different name: "No content databases are available for this operation"

    http://support.microsoft.com/kb/926284

    Changes that you make to the "List View" Web Part are not retained after you save the site as a template in Windows SharePoint Services 3.0

    http://support.microsoft.com/kb/926283

    SharePoint Server 2007 article page content is added in the Pages library and not in the document library in which the article page was created

    http://support.microsoft.com/kb/926061

    Error message when you try to restore a Windows SharePoint Services 3.0 Web site: "The site collection could not be restored. Please make sure the content databases are available and have sufficient free space"

    http://support.microsoft.com/kb/925765

    How to configure SharePoint to let you search OneNote 2007 content on SharePoint sites

    http://support.microsoft.com/kb/925609

    A crawl does not make any progress and the crawl logs show no new crawled documents in SharePoint Server 2007

    http://support.microsoft.com/kb/925198

    You may not see the values of the promoted fields when you upload an InfoPath 2007 form to a document library

    http://support.microsoft.com/kb/925190

    How to move a WMSDE content database that resides on a Windows SharePoint Services 2.0 server to a Windows SharePoint Services 3.0 server

    http://support.microsoft.com/kb/925083

    Error message when you try to upload a large file to a document library on a Windows SharePoint Services 3.0 site: "Request timed out"

    http://support.microsoft.com/kb/924464

    You do not see a link to the home page of the portal site in a personal site that you created in SharePoint Server 2007

    http://support.microsoft.com/kb/923906

    When you try to open a folder in a Windows SharePoint Services 3.0 document library in Explorer View, the folder does not open

    http://support.microsoft.com/kb/923905

    The tab on the top link bar is not selected when you connect to a Windows SharePoint Services 3.0 subsite

    http://support.microsoft.com/kb/923904

    Error message when you try to upgrade Windows SharePoint Services 2.0 to Windows SharePoint Services 3.0: "Upgrade has encountered one or more lists that were not updated by Prescan.exe and must exit"

    http://support.microsoft.com/kb/923902

    Values that were previously associated with a field are reset when you run a custom code that calls the Lists.UpdateList method to update a list view in SharePoint Products and Technologies

    http://support.microsoft.com/kb/923592

    Error message when you use SharePoint Central Administration to run a content deployment job in SharePoint Server 2007: "Microsoft.SharePoint.SPException': 'A folder with the name _catalogs/masterpage/Forms/Page Layout already exists"

    http://support.microsoft.com/kb/920277

    Windows Internal Database is not listed in the Add or Remove Programs tool and is not removed when you remove Windows SharePoint Services 3.0 from the computer

    http://support.microsoft.com/kb/919547

    You cannot log on to a SharePoint Server 2007 site after you change the computer that is used as the dedicated front-end Web server

    http://support.microsoft.com/kb/916894

    Error message when you install SharePoint Portal Server 2007 or Windows SharePoint Services 3.0: "Failed to create sample data"

    http://support.microsoft.com/kb/911149

    Error message in Internet Explorer when you try to access a Web site that requires Kerberos authentication on a Windows XP-based computer: "HTTP Error 401 - Unauthorized: Access is denied due to invalid credentials"

    http://support.microsoft.com/kb/908956

    Support information about defining the local address of a SharePoint Portal Server 2003 or SharePoint Server 2007 content index to be on a System Area Network device

    http://support.microsoft.com/kb/871155

    You are prompted to enter your user name and your password when you open an Office document in SharePoint Server 2007, in SharePoint Portal Server 2003, or in Windows SharePoint Services

    February 19

    談論主題 MOSS站点实现用户积分排名

     

    引述

    MOSS站点实现用户积分排名

    我们希望增加MOSS站点的互动性,希望鼓励用户参与讨论和发表文章,因此用户积分功能是必不可少的。

    思路:MOSS数据库中有一张视图即userdata 表,里面存储了用户所有自定义的内容,其中就包括了其发布的文档、文章、讨论回复等等,换句话说我们可以通过统计userdata 中用户发布的内容来算出用户的积分。同时,我们也希望把用户对站点的点击数也算到积分中,这就需要WSS3。0中新增的audit功能来实现。

    首先来看看实现后的效果:

    积分排名:

    20070523170433266

    积分权重:

    new02

    一、创建积分类别权重表Integral

    表中包含三个字段:IntegralID(标识ID) IntegralType(积分类别) Multiples(积分权重)

    USE [WSS_Content_80]
    GO
    /****** 对象:  Table [dbo].[Integral]    脚本日期: 09/11/2007 08:38:57 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Integral](
        [IntegralID] [int] IDENTITY(1,1) NOT NULL,
        [IntegralType] [nvarchar](20) NULL,
        [Multiples] [float] NULL,
     CONSTRAINT [PK_Integral] PRIMARY KEY CLUSTERED
    (
        [IntegralID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    二、创建以下存储过程

    1、积分排名存储过程

    积分类别主要有三类:文档、文章、讨论回复,三者和权重相乘后累加得到积分。(存储过程中还扩展了一个积分类别是点击量,如果你没有启用audit item功能,请注释掉此部分)

    USE [WSS_Content_80]
    GO
    /****** 对象:  StoredProcedure [dbo].[cus_AuditRank]    脚本日期: 09/11/2007 08:48:26 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    alter PROCEDURE [dbo].[cus_AuditRank]
    AS

    declare @Multiples1 float,@Multiples2 float,@Multiples3 float--积分权重
    select @Multiples1=Multiples from Integral where IntegralID=1
    select @Multiples2=Multiples from Integral where IntegralID=2
    select @Multiples3=Multiples from Integral where IntegralID=3

    create table #Click(UserId int,ClickNum int)
    create table #DocUpload(UserId int,DocNum int)
    create table #DisCussUpload(UserId int,DisCussNum int)
    create table #NewsUpload(UserId int,NewsNum int)
    --
    create table #list(UserId int)
    insert into #list(UserId)
    select distinct tp_author from userdata where  not tp_author = 1073741823
    --点击量
    insert into #Click(UserId,ClickNum)
    select UserId,count(UserId) as CountNum from AuditData
    where (not UserId=1073741823) and (not UserId=13) and Event = 3 and itemtype=1
    group by UserId --order by countnum desc
    --文档数
    insert into #DocUpload(UserId,DocNum)
    select tp_author,count(tp_author) as CountNum from userdata
    where not tp_author = 1073741823 and  tp_contenttype =  N'文档'
    group by tp_author
    --讨论数
    insert into #DisCussUpload(UserId,DisCussNum)
    select tp_author,count(tp_author) as CountNum from userdata
    where not tp_author = 1073741823 and  tp_contenttype =  N'讨论'
    group by tp_author
    --消息数
    insert into #NewsUpload(UserId,NewsNum)
    select tp_author,count(tp_author) as CountNum from userdata
    where not tp_author = 1073741823 and tp_contenttype =  N'消息'
    group by tp_author

    select l.*,ISNULL(DocNum,0) DocNum,ISNULL(DisCussNum,0) DisCussNum,ISNULL(NewsNum,0) NewsNum
    ,ISNULL(DocNum,0)*@Multiples1+ISNULL(DisCussNum,0)*@Multiples2+ISNULL(NewsNum,0)*@Multiples3 IntegralNum from #list l
    FULL OUTER JOIN #DocUpload d on l.UserId=d.UserId
    FULL OUTER JOIN #DisCussUpload dis on l.UserId=dis.UserId
    FULL OUTER JOIN #NewsUpload n on l.UserId=n.UserId
    where not ( DocNum is NULL and DisCussNum is NULL and NewsNum is NULL)
    order by IntegralNum desc

    drop table #Click
    drop table #DocUpload
    drop table #DisCussUpload
    drop table #NewsUpload
    drop table #list

    2、获取积分类别

    GO
    /****** 对象:  StoredProcedure [dbo].[cus_AuditType]    脚本日期: 09/11/2007 11:04:31 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    create PROCEDURE [dbo].[cus_AuditType]
    AS

    select * from Integral

    3、修改积分类别权重

    GO
    /****** 对象:  StoredProcedure [dbo].[cus_AuditTypeModify]    脚本日期: 09/11/2007 11:09:06 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    create PROCEDURE [dbo].[cus_AuditTypeModify]
    @IntegralID int,@Multiples float
    AS

    update Integral set Multiples=@Multiples where IntegralID=@IntegralID

    三、创建自定义应用程序页面 AuditRankViewer.aspx

     

    1、修改web.config

    需要修改C:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\LAYOUTS\web.config文件,支持中文字符集,添加<globalization fileEncoding="gb2312" />和数据库连接字符串。修改后的文件如下:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <configuration>
      <system.web>
        <compilation batch="false" batchTimeout="600" maxBatchSize="10000" maxBatchGeneratedFileSize="10000" />
        <httpHandlers>
          <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory, System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </httpHandlers>
        <customErrors mode="On" />
        <httpRuntime executionTimeout="360" />
        <globalization fileEncoding="gb2312" />
      </system.web>
    <appSettings>
            <!--   此处显示用户应用程序和配置的属性设置。-->
            <add key="MOSSData" value="server=localhost;database=WSS_Content_80;user id=sa;password=*****"  />
        </appSettings>
      <location path="upload.aspx">
        <system.web>
          <httpRuntime maxRequestLength="2097151" />
        </system.web>
      </location>
      <location path="ctdmsettings.aspx">
        <system.web>
          <httpRuntime maxRequestLength="2097151" />
        </system.web>
      </location>
      <location path="ChangeContentTypeOptionalSettings.aspx">
        <system.web>
          <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />
        </system.web>
      </location>
      <location path="MngField.aspx">
        <system.web>
          <httpRuntime executionTimeout="3600" />
        </system.web>
      </location>
      <location path="fldpick.aspx">
        <system.web>
          <httpRuntime executionTimeout="3600" />
        </system.web>
      </location>
      <location path="ManageContentTypeField.aspx">
        <system.web>
          <httpRuntime executionTimeout="3600" />
        </system.web>
      </location>
    </configuration>

    2、创建AuditRankViewer.aspx

    代码如下:

    <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" Culture="zh-CN"  UICulture="zh-CHS" %>

    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Configuration" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
      Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <script runat="server">

      protected override void OnLoad(EventArgs e) {

          if (!IsPostBack)
          {
              Label1.Text = this.Page.User.Identity.Name;
              //积分排名
              BindGridToSource();
              //积分权重
              BindGridView2();
              //if(this.Page.User.Identity.Name == "LITWARE\林钉")
              //{
                //Panel1.Visible = true;
              //}
          }
      }

        void BindGridToSource()
        {
            SqlConnection sqlCn;
            sqlCn = new SqlConnection(ConfigurationManager.AppSettings["MOSSData"]);
            SqlCommand sqlCmd = new SqlCommand("cus_AuditRank", sqlCn);
            SqlDataReader sqlRd;

            try
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCn.Open();
                //sqlCmd.Parameters.Add("@receiver", SqlDbType.NVarChar, 50).Value = speople = this.UserName;//lab_dqyh.Text;
                sqlRd = sqlCmd.ExecuteReader();
                GridView1.DataSource = sqlRd;
                GridView1.DataBind();
            }
            catch (Exception)
            {

            }
            finally
            {
                sqlCn.Close();
            }
        }

        void BindGridView2()
        {
            SqlConnection sqlCn;
            sqlCn = new SqlConnection(ConfigurationManager.AppSettings["MOSSData"]);
            SqlCommand sqlCmd = new SqlCommand("cus_AuditType", sqlCn);
            SqlDataReader sqlRd;

            try
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCn.Open();
                //sqlCmd.Parameters.Add("@receiver", SqlDbType.NVarChar, 50).Value = speople = this.UserName;//lab_dqyh.Text;
                sqlRd = sqlCmd.ExecuteReader();
                GridView2.DataSource = sqlRd;
                GridView2.DataBind();
                if (Label1.Text == @"MOSSCENTERM\xx" || Label1.Text == @"MOSSCENTERM\administrator" || Label1.Text == @"MOSSCENTERM\xx")//41
                //if (Label1.Text == @"LITWARE\xx" || Label1.Text == @"LITWARE\administrator")//30.6
                    GridView2.Columns[2].Visible = false;
                else
                {
                    GridView2.Columns[3].Visible = false;
                    Button1.Visible = false;
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                sqlCn.Close();
            }
        }

      string GetUserNameById(int UserId, SPWeb site) {
        try {
          return site.SiteUsers.GetByID(UserId).Name;
          //return site.Users.GetByID(UserId).Name; - YOU CANNOT USE SPWeb.Users collection here
        }
        catch {
          return UserId.ToString();
        }
      }

      protected void cmdRefreshPage_Click(object sender, EventArgs e) {
        Response.Redirect(Request.RawUrl);
      }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                SPSite siteColl = SPContext.Current.Site;
                SPWeb site = SPContext.Current.Web;
                e.Row.Cells[0].Text = GetUserNameById(Convert.ToInt32(e.Row.Cells[0].Text), site);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void dgIntegral_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemIndex >= 0)
            {
                System.Web.UI.WebControls.TextBox tbInt;

                tbInt = (TextBox)e.Item.FindControl("tbInt");
                tbInt.Text = e.Item.Cells[2].Text.ToString();
            }

        }

        private void ModifyAuditType(int IntegralID, float Multiples)
        {
            SqlConnection sqlCn;
            sqlCn = new SqlConnection(ConfigurationManager.AppSettings["MOSSData"]);
            SqlCommand sqlCmd = new SqlCommand("cus_AuditTypeModify", sqlCn);
            SqlDataReader sqlRd;

            try
            {

                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCn.Open();
                sqlCmd.Parameters.Add("@IntegralID", SqlDbType.Int).Value = IntegralID;
                sqlCmd.Parameters.Add("@Multiples", SqlDbType.Float).Value = Multiples;

                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Page.Response.Write(ex.ToString());
            }
            finally
            {
                sqlCn.Close();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int sum = GridView2.Rows.Count;
            for (int i = 0; i < sum; i++)
            {

                System.Web.UI.WebControls.TextBox TextBox1;
                TextBox1 = (TextBox)GridView2.Rows[i].FindControl("TextBox1");
                if (TextBox1.Text.ToString() == GridView2.Rows[i].Cells[2].Text.ToString())
                {
                    ;
                }
                else//只有存在变更的行才进行提交
                    ModifyAuditType(Convert.ToInt32(GridView2.Rows[i].Cells[0].Text.ToString()), Convert.ToSingle(TextBox1.Text.ToString()));

            }
        }

        protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                System.Web.UI.WebControls.TextBox TextBox1;
                TextBox1 = (TextBox)e.Row.FindControl("TextBox1");
                TextBox1.Text = e.Row.Cells[2].Text.ToString();
            }
        }
    </script>

    <asp:Content ID="Content6" ContentPlaceHolderID="PlaceHolderMain" runat="server">
      <asp:Button ID="cmdRefreshPage" runat="server" Text="刷新" OnClick="cmdRefreshPage_Click" />&nbsp;&nbsp;
        &nbsp; 积分=文档数×文档权重+文章数×文章权重+回复数×回复权重
      <hr />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField="UserId" HeaderText="用户" />
                <asp:BoundField DataField="DocNum" HeaderText="文档数" />
                <asp:BoundField DataField="DisCussNum" HeaderText="文章数" />
                <asp:BoundField DataField="NewsNum"  HeaderText="回复数" />
                <asp:BoundField DataField="ClickNum" HeaderText="点击数" />
                <asp:BoundField HeaderText="积分" DataField="IntegralNum" />
            </Columns>
        </asp:GridView>
        &nbsp;&nbsp;
        <asp:Panel ID="Panel1" runat="server" Width="100%">
            积分权重
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="保存并提交" />&nbsp;&nbsp;
            <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
            <hr />
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound">
                <Columns>
                    <asp:BoundField DataField="IntegralID" HeaderText="ID" Visible="False" />
                    <asp:BoundField DataField="IntegralType" HeaderText="积分类别" />
                    <asp:BoundField DataField="Multiples" HeaderText="权重" />
                    <asp:TemplateField HeaderText="编辑权重值(倍数)">
                        <EditItemTemplate>
                            &nbsp;
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </asp:Panel>
        &nbsp;&nbsp;<br />
        &nbsp;
            &nbsp;<br />
            <br />
    </asp:Content>

    <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
      SPAudit Log Viewer
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
      runat="server">
        积分排名
    </asp:Content>

    3、复制AuditRankViewer.aspx

    创建后,需要将该页面复制到C:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\LAYOUTS目录下。

    February 18

    MOSS 2007 各版本資訊

    • MOSS 20071 or WSS 3.0 SP1           12.0.0.6219
    • MOSS 20071 or WSS 3.0 October public update               12.0.0.6039
    • MOSS 20071 or WSS 3.0 August 24, 2007 hotfix package 12.0.0.6036
    • MOSS 20071 or WSS 3.0 RTM           12.0.0.4518
    • MOSS 20071 or WSS 3.0 Beta 2 TR  12.0.0.4407
    • MOSS 20071 or WSS 3.0 Beta 2:       12.0.0.4017
    • Office 12 (PDC image - pre-beta):      12.0.0.3111 (This version of Office does not have a support link in the Add/Remove programs dialog box).
    February 14

    If you want to attach a MDF without LDF

    1. Create a new database with the same name and same MDF and LDF files
    2. Stop sql server and rename the existing MDF to a new one and copy the original MDF to this location and delete the LDF files.
    3. Start SQL Server
    4. Now your database will be marked suspect 5. Update the sysdatabases to update to Emergency mode. This will not use LOG files in start up
     

    Sp_configure "allow updates", 1
    go
    Reconfigure with override
    GO
    Update sysdatabases set status = 32768 where name = "BadDbName"
    go
    Sp_configure "allow updates", 0
    go
    Reconfigure with override
    GO


    5. Restart sql server. now the database will be in emergency mode
    6. Now execute the undocumented DBCC to create a log file

    DBCC REBUILD_LOG(dbname,'c:\dbname.ldf') -- Undocumented step to create a new log file.
    (replace the dbname and log file name based on ur requirement)

    7. Execute sp_resetstatus <dbname>
    8. Restart SQL server and see the database is online.

    February 12

    Wildcard People Search on MOSS 2007

    Posted by: Ramon Scott
    4/19/2007

    Unfortunately out-of-the-box Microsoft Office SharePoint Server 2007 does not play nice with wildcard searches. This is particularly troublesome when searching for people with hard to spell names.

    Here's a quick solution for a adding a web part to the home page that allows for searching for people using first, last or a combination of names. Wildcards are supported on either.

    So, entering a first name of Rob would return results for Rob, Robert, Roberta, Robbie, etc. Likewise, a last name search for Smit would return results for Smith, Smits, Smitkerson, etc.

    To use this, just add a content editor web part to the moss home page and paste the code below into the source view. The form will submit to the default people search results page.

    <script language="javascript">
    //function to handle enter on keyboard
    function txtWildPeopleFinder_KeyDown(e)
    {
      if (e.keyCode == 13 || e.keyCode==10)
      {
        e.returnValue=false;
        DoWildPeopleSearch();
        return false;
      }
      else
        return true;
    }
    //escape apostrophes in search strings
    function escapestr(str)
    {
    return str.replace("'","%22");
    }

    //search function
    function DoWildPeopleSearch()
    {
    var firstname = escapestr(document.all["firstname"].value);
    var lastname =  escapestr(document.all["lastname"].value);
    var url;

    //search on last name
    if(firstname == "")
    {
    url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" + lastname;
    window.location=url;
    return;
    }
    //search on first name
    if(lastname == "")
    {
    url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" + firstname;
    window.location=url;
    return;
    }

    //first and last
    url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname +  "%20FirstName%3A" + firstname;
    window.location=url;
    return;
    }
    </script>

    <table cellpadding="3" cellspacing="0" border="0" width="100%" ID="Table3">
    <tr>
      <td width="80" nowrap>
       First Name:
      </td>
      <td width="100%">
       <input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
      </td>
    </tr>
    <tr>
      <td width="80" nowrap>
       Last Name:
      </td>
      <td>
       <input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
      </td>
    </tr>
    <tr>
      <td> &nbsp; </td>
      <td>
       <input type="button" onclick="DoWildPeopleSearch()" value="Search">
      </td>
    </tr>
    </table>

    Sunday, January 21, 2007 5:16 AM polo 透過 Vista 搜尋功能, 整合 Search SharePoint 網站內容

    • Click on Start Button
    • Type Gpedit.msc, Group Policy Editor will open (Click Allow if prompted for elevated privileges)
    • Navigate down and expand the following Tree Nodes User Config > Administrative Templates > "Windows Components" > Instant Search
    • Double Click Custom Instant Search Internet Search Provider
    • Choose to Enable
    • Enter Search My SharePoint Site
    • Enter http://YOURSERVER/searchcenter/pages/search_results.aspx?k=%w for URL.

      NOTE: The %w will be substituted at runtime with your search text url encoded.

      Replace YOURSERVER with your SharePoint server.

    • Click OK
    • Close Group Policy Editor
    • Reboot or run the following command in a command window as Administrator gpupdate /force

    From Refines.Info["Polo Lee"]

    上傳檔案並使用 Hashtable 註記 MetaData 值

    ///=============================================================================================

    /// Upload File Method.1

    ///=============================================================================================

    SPSite sp = new SPSite(“URL of the site collection”);     

    SPWeb site = sp.OpenWeb();      

    SPFolder folder = site.GetFolder(“Document Library Name”);     

    SPFileCollection files = folder.Files; 

    FileStream fStream = File.OpenRead(“C:\\upload.doc”); //path of the file to upload     

    byte[] contents = new byte[fStream.Length];     

    fStream.Read(contents, 0, (int)fStream.Length);     

    fStream.Close();      

    Hashtable MetaDataTable = new Hashtable();     

    MetaDataTable.Add(“Comments”, “Hello World”);      

    SPFile currentFile = files.Add(“URL of the document library/upload.doc”, contents, MetaDataTable, true); 

    ///=============================================================================================

    ///=============================================================================================

    /// Upload File Method.2

    ///=============================================================================================

    //Using required, especially System.IO;
    using System.Collections.Generic;
    using System.Collections;
    using System.Text;
    using Microsoft.SharePoint;
    using System.IO;
    namespace DocImport
    {
            public class DocManagement {

            //Some variables
            private string _DestUrlPath = string.Empty;
            private string _DestFolder = string.Empty;
            private SPSite _site = null;
            private SPWeb _web = null;
           

            public DocManagment(string DestUrl, string DestFolder) {
            _DestUrlPath = DestUrl;
            _DestFolder = DestFolder;
            _site = new SPSite(_DestUrlPath);
            _web = _site.OpenWeb();
           

            }
           

            private bool _uploadDocument(string pdfFile, string txtFile) {

            try {
                           //This is mandatory for avoiding an error
                           _web.AllowUnsafeUpdates = true;
            

                          //Use the list as a folder
                          SPFolder folder = _web.GetFolder(_DestFolder);
                          SPFileCollection files = folder.Files;
           

                          //Get the file
                          FileStream fStream = File.OpenRead(pdfFile);
                          HashTable MetaDataTable = new HashTable();
                          MetaDataTable.Add("nom de colonne", "valeur");
           

                          //Set the destination url for SharePoint
                          string url = _DestUrlPath + _DestFolder + "/" + Path.GetFileName(pdfFile);
           

                          //Add document to the list with metadata, and overwrite an existing document with the same name
                          SPFile currentFile = files.Add(url, fStream, MetaDataTable, true);
                          fStream.Close();
                          return true;
                   }

             catch (Exception x) {
                         throw new Exception(x.Message);
             }
    }
    }

    February 02

    Talking about MOSS 2007 Item Level Permissions

     

    Quote

    MOSS 2007 Item Level Permissions
    A little off the normal subject here, this post isn't to with Windows Live or MSN (although may apply to Office Live, I'm not sure).
    As many of you will know by now, Office 2007 has RTM'd.  I've been working with MOSS 2007 (Sharepoint) and WSS 3 for a number of months now at work as we have a massive campus wide program we're trying to implement.
    One of the really neat (and much requested) new things that MOSS 2007 provides you with is the ability to assign permissions down at the item level rather than just at the DocLib level as per Sharepoint 2003.
    This is indeed wonderful and it would be even better if there was any sort of documentation on how to do this programatically (it's very easy to do through the front end GUI). I've been working on this problem for the past couple of days now, trying to scour the web for tidbits of information as to how the new security system works from an programers perspective and turning up no information whatsoever.
    So off to the SDKs. I downloaded the latest WSS 3 SDK (which is still Beta 2 TR, where is the RTM SDK?) and plowed my way through that. Again there is very little information in there unless you actually know what you're looking for.  So between the SDK and some playing around, I finally managed to figure it out.
    What I was trying to accomplish was relatively simple, program a webpart that would allow a user to upload a document. The webpart would then store the document in a pre-determined doclib and assign permissions to the object at the item level. 
    For my testing I created a doclib called "ResearchAdmin" and had a simple text document (Test01.txt) that I was going to upload and assign permissions to.
     
    Here's the code that will allow you to do this :-
     
    First off import the relavent libraries :-

    using System;
    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Serialization;
    using System.Security;
    using System.Security.Permissions;
    using System.IO;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;

    [assembly:

    AllowPartiallyTrustedCallers]

    //Next define your class and add a couple of controls to it (a label for information purposes and testing output, a
    //
    fileupload control and a button to submit)

    namespace

    RAWFWebPart

    {

    [

    Guid("52715fc3-fe1a-4148-a867-781fb5e94a90")]

    public class RAWFWebPart : System.Web.UI.WebControls.WebParts.WebPart

    {

    #region

    Controls

    private System.Web.UI.WebControls.FileUpload fleUpload = new System.Web.UI.WebControls.FileUpload();

    private Label lblInstructions = new Label();

    private Button btnSubmit = new Button();

    #endregion

     

    //Next get your custom webpart to display the controls onscreen

     

    #region Rendering

    protected override void CreateChildControls()

    {

    //Initialize data

    lblInstructions.Text =

    "Please select the file to upload.";

    btnSubmit.Text =

    "Upload";

    //Add event handlers

    btnSubmit.Click +=

    new EventHandler(btnSubmit_Click);

    this.Controls.Add(fleUpload);

    this.Controls.Add(lblInstructions);

    this.Controls.Add(btnSubmit);

    }

    protected override void RenderContents(HtmlTextWriter writer)

    {

    //Render the controls

    lblInstructions.RenderControl(writer);

    writer.WriteBreak();

    fleUpload.RenderControl(writer);

    writer.WriteBreak();

    btnSubmit.RenderControl(writer);

    }

    protected override void Render(HtmlTextWriter writer)

    {

    RenderContents(writer);

    }

    #endregion

     

    //And this is where the fun takes place, in the event handler.

    //You upload your file into a memory stream then place it in the appropriate

    //doclib. Then once it's in the library, you assign item level permissions to it.

     

    #region

    Event Handlers

    void btnSubmit_Click(object sender, EventArgs e)

    {

    SPWeb myweb = SPControl.GetContextWeb(

    this.Context);

    SPFolder folder = myweb.Folders[

    "ResearchAdmin"];

    if (fleUpload.HasFile)

    {

    //First get the name of the file uploaded

    int lastSlash = fleUpload.PostedFile.FileName.LastIndexOf("\\");

    string fName = fleUpload.PostedFile.FileName.Substring(lastSlash + 1);

    //Upload the file into memory

    Stream fStream = fleUpload.PostedFile.InputStream;

    byte[] file = new byte[fStream.Length];

    fStream.Read(file, 0, (

    int)fStream.Length);

    fStream.Close();

    //Now upload the file into the doclib.

    try

    {

    myweb.Files.Add(folder.Url +

    "/" + fName, file, true);

    lblInstructions.Text =

    "File Uploaded Successfully";

    //Now that the file has been uploaded successfully

    //we need to redirect the user to the K2 workflow page.

    //First off we need to collect some data (NOTE: The code for this has been removed)

    string username = this.Context.User.Identity.Name.ToString();

    string formurl = "http://sps2007/" + folder.Url + "/" + fName;

    string folio = fName.Substring(0, fName.Length - 4).ToString();

    string doc = fName;

    string fullfilename = folder.Url + "/" + fName;

    try

    {

    //Now we assign item level permissions.

    //First off get a reference to the doclib

    SPListCollection lists = myweb.Lists;

    SPList lst = lists[

    "ResearchAdmin"];

    SPListItemCollection listitems = lst.Items;

     

    //You will need this GUID later to get the actual listitem

    Guid itemid = new Guid();

     

    foreach (SPListItem lstitem in listitems)

    {

    if (lstitem.Name == fName)

    {

    itemid = lstitem.UniqueId;

    }

    }

    //Use the guid to get the listitem you want to set permission to

    SPListItem listitem = listitems[itemid];

     

    //Get a reference to the currently logged in user as that's who you'll be

    //setting permissions for.

    SPUser user = myweb.CurrentUser;

     

    //This gets a list of all roles the user has for this item

    SPRoleAssignment assign = listitem.RoleAssignments.GetAssignmentByPrincipal(user);

     

    //Create a new Role Assignment based on the current user

    SPRoleAssignment myrole =

    new SPRoleAssignment(user);

     

    //Get a Role Definition. This is really a permission set. I created

    //a new permission level for testing and called it PI.

    SPRoleDefinition def = myweb.RoleDefinitions[

    "PI"];

     

    //Now add this permission to the users permissions

    myrole.RoleDefinitionBindings.Add(def);

     

    //And finally add the user and his permissions for this object to the

    //object itself and update it.

    listitem.RoleAssignments.Add(myrole);

    listitem.Update();

    }

    catch (Exception ex)

    {

    lblInstructions.Text = ex.Message.ToString();

    }

    }

    catch (Exception ex)

    {

    lblInstructions.Text = ex.Message.ToString();

    }

    }

    else

    {

    lblInstructions.Text =

    "No File found";

    }

    }

    #endregion

    }

    }

    Talking about MOSS 2007 web part pages query strings

     

    Quote

    MOSS 2007 web part pages query strings
    Recently i'm working in a project in which a custom control that adds web parts programmatically on the web part pages, and we needed to redirect to a page and open it in the  edit mode, i tried to use the query string paramaters we used in sps 2003  ( Mode=Edit, PageView=Shared ... etc ) i searched a little bit till i figured them out:
    ControlMode=Edit&DisplayMode=Design , with these parameters the web part pages will be opened in the edit mode.