Friday, December 03, 2010

修改SharePoint網站之清單"建立者"欄位

Environment
Server: Win2003 + SharePoint Service 3

需求: 當透過WSS UI的「儲存清單為範本」+「包括內容」選項將清單匯出後,再匯入時,所有清單項目的「建立者」欄位都會變成匯入人的名字。如果資訊人員佛心來的想替使用者改掉... 是可以做的,寫程式囉。

利用Microsoft提供的SharePoint API: Microsoft.SharePoint.dll。這支dll可以在SharePoint server上的\\Computer_Name\Drive$\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI 內找到。

但是,如果你覺得把他複製出來到自己本機開發那就錯了。這麼做應該會遇到「無法載入檔案或組件或其相依性的其中之一」的錯誤,就像這篇SharePoint Forums上的討論,請直接在裝有SharePoint Service的server上做開發.. 如果有測試機器是再好不過的,就可以參考這篇文章(Can we update the values of “Created By”, "Modified By” columns in SharePoint lists?)直接在Visual Studio上參考上述組件做開發。

如果你正好沒有測試環境,而且也無法在production上安裝VisualStudio這麼龐大的怪物的話,就參考這篇文章(Updating the “Created By” and "Modified By” Columns in SharePoint lists using POWERSHELL)。沒錯! 就是用POWERSHELL。這也是我用的方法。

script:

   1:  # Get the SharePoint Assembly 


   2:  # You will need to run this on the SharePoint Server


   3:  [Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 


   4:   


   5:  # create a new object called $SPSite


   6:  # Make sure you have the last “/” in the url on the site 


   7:  # allow $SPWeb to be the OpenWeb from the site


   8:  $SPSite = New-Object Microsoft.SharePoint.SPSite("http://server-name/")


   9:  $SPWeb = $SPSite.OpenWeb() 


  10:   


  11:  # Get the list ModifyCreatedBy 


  12:  $SPList = $SPWeb.Lists["ListName"] 


  13:   


  14:  # Get the Collection of the List Items


  15:  $SPListItemCollection = $SPList.Items 


  16:   


  17:  # iterate the Collection


  18:  foreach ($ListItem in $SPListItemCollection) 


  19:  {


  20:   


  21:    # The user in this case was UserA with id of 8 from the SPWeb users 


  22:    $SPFieldUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,8,"UserA") 


  23:   


  24:    $ListItem["Author"] = $SPFieldUserValue


  25:   


  26:    # Note: Editor will be the account that you are running the Powershell under unless you update Editor as well 


  27:    # ListItem["Editor"] = $SPFieldUserValue


  28:   


  29:    $ListItem.Update() 


  30:  } 


  31:   


  32:  $SPWeb.Update() 


  33:   


  34:  # Still TODO Disposes, Error Checking, Change to take Parameters, etc


  35:   



 
上面的script是改了整個指定清單的建立者欄位,如果你還需要先判斷是那些文件,可以參考一下MSDN Library看看SPListItem還有哪些properities可以用。若是powershell語法不熟的話(尤其他又喜歡跟一般語法同.... 特別是比較運算子...),請參考reference#4, #5,或自行google。



嗯.. 大概就以上資訊,即可作業!!



Ref:




  1. [SharePoint Forums] Could not find Microsoft.SharePoint.Library.dll


  2. [MSDN Blog] Can we update the values of “Created By”, "Modified By” columns in SharePoint lists?


  3. [MSDN Blog] Updating the “Created By” and "Modified By” Columns in SharePoint lists using POWERSHELL


  4. [TechNet 技術文件庫] Running Windows PowerShell Scripts


  5. [賴榮樞的軟體資訊誌] scripting_PowerShell tag


  6. [MSDN Library] Microsoft.SharePoint Namespace

Monday, November 15, 2010

poppassd + roundcube on FreeBSD

最近因為被roundcube的美貌所吸引,所以正在考慮是否拿它來當webmail。roundcube最大的特點就是: 相當美+相當陽春。

紀錄一下poppassd跟roundcube怎麼搭配,讓使用者可以在web介面上直接改密碼,而不需要登入freebsd系統.. roundcube的安裝部分就不介紹了,直接來poppassd的部分。

Environment:
OS: FreeBSD 8.1-RELEASE-p1
roundcube: 0.4.2
poppassd: 4.0_3

STEP1: Install poppassd

# cd /usr/ports/mail/poppassd/
# make install clean

By default, you can find the binary in /usr/local/libexec

STEP2: Startup setting

# man poppassd

Modify /etc/inetd.conf AND /etc/services AND /etc/syslog.conf as describe in the man page.

STEP3: Auto-start inetd when reboot
Modify /etc/rc.conf AND add:

# inetd

inetd_enable="YES"

STEP4: restart inetd

# /etc/rc.d/inetd restart

 

STEP5: Config roundcube plugin
Modify /usr/local/www/roundcube/plugins/password/config.inc.php

// Select a driver to use, see README for more driver name

$rcmail_config['password_driver'] = 'poppassd';

STEP6: Add roundcube plugin
Modify /usr/local/www/roundcube/config/main.inc.php

// List of active plugins (in plugins/ directory)
$rcmail_config['plugins'] = array('password');

STEP FINAL: Restart roundcube and apache

 

Ref:

  1. [FRESH ports] poppassd
  2. Poppassd – Installation and Management Guide
  3. roundcube wiki – plugins/password
Thursday, October 21, 2010

iSCSI target crash when selecting ‘Device’ node

OS: Windows Storage Server 2003 R2
iSCSI target version: 3.1.3412

如題,一個很久以前就注意到的問題,不過因為沒有急迫性,就一直不理他XD。這兩天因為要整理一些空間出來用,只好處理一下。

於是找到一篇HP論壇裡的討論串,裡面有人提到是微軟的一個更新造成的...

請找KB973507

這個更新是2009/8/11出來的,如果有人遇到同樣的問題,大概也是這個時點之後,把這個更新移除後重開機,iSCSI target就可以正常使用了~

另外也有一份文件提到:

Issue: Installing Microsoft security update KB973507 results in the Microsoft iSCSI Software Target not displaying
iSCSI target devices when the Devices node is selected in the iSCSI Target management console.

Ref:

  1. [HP IT Resource Center Forums] AiO 600 - problem with Microsoft iSCSI target snapin
  2. [pdf] HP StorageWorks P4000 Unified NAS Gateway Release Notes
Thursday, September 30, 2010

Oracle shutdown hangs: forgot the ‘immediate’ option

一個簡單的小問題,不過還滿常發生的=   =||

一般需要關閉資料庫時,都會下'shutdown immediate’指令,有了immediate選項,Oracle不需等待所有連線關閉。反之,若只有下'shutdown'指令,也就是'shutdown normal',Oracle就會等到所有連線都結束後才關閉,通常都關不下來... 這時候就算又開了新的連線想重下指令,都會收到類似"Not connected to Oracle"這類的訊息.. 這時候!!

可以另外開一個新連線這麼做:

SQL> conn sys as sysdba
輸入密碼:
連線至閒置的執行處理.
SQL> startup force
已啟動 ORACLE 執行處理.
……(資料庫已掛載./資料庫已開啟.)
SQL> shutdown immediate

這樣就可以成功的把資料庫關下來囉~

另一邊原本正在shutdown的視窗可能會看見如下過程:

SQL> shutdown
ORA-03113: 通訊通道上出現 EOF

SQL> ^F^D
SP2-0042: 未知的命令 "" - 此行的剩餘部份被略過不予處理

完工!

Thursday, September 16, 2010

office: 使用萬用字元進行尋找/取代作業

今天發現office的尋找功能還滿強大的,介紹一些使用萬用字元搜尋/取代的方法:首先最基本的就是要會打開「尋找及取代」的視窗XD,在「更多(M)>>」選項裡把「使用萬用字元(U)」選項給勾起來。

  • 尋找符合「HH:MM:SS」的時間格式: 最簡易且不嚴謹的寫法可以用「??:??:??」。「?」表示任何單一字元,所以如果你的文件裡有「AA:BB:CC」這樣的字串,它也會符合尋找目標,但卻不符合我們只想尋找時間格式的目的。所以可以改寫成「[0-9]{2}:[0-9]{2}:[0-9]{2}」,就是三組「[0-9]{2}」被兩個冒號隔開來,其中「[0-9]」表示0到9之間的其中一個數字,「{2}」表示前一個字元或運算式必須出現2次。所以利用三組「[0-9]{2}」與冒號就可以找出符合的格式。
  • 在找到的「HH:MM:SS」時間格式前後加上「*」: 這時候就要需要取代功能的搭配了。在取代的頁籤裡,「取代為」的表示式該怎麼寫呢? 我希望找到所有的符合的時間格式並在他前後加上星號,卻不希望更改了時間的值。一開始嘗試用「*[0-9]{2}:[0-9]{2}:[0-9]{2}*」,結果他就把所有時間格式整個直接取代成「*[0-9]{2}:[0-9]{2}:[0-9]{2}*」的字樣OTZ。正確做法應該是把尋找目標寫成「([0-9]{2}):([0-9]{2}):([0-9]{2})」, 取代寫成「*\1:\2:\3*」。「\1」, 「\2」, 「\3」依序代表尋找目標的三組括號裡的值! 這個技巧主要用在你真正的目的不是「取代」,而是利用尋找到的目標再做一些位置上的變化或像此處加上其他字元符號的應用。

以上兩個就是今天有用到的精隨啦~ 當然還有很多種變化,像是{2,}則表示前面的字元或運算式至少要出現2次,若是{2,4}就表示前面的字元或運算式須出現2-4次。另外在不使用萬用字元的情況下也可用「代碼」來尋找特殊的格式或字元:

  • 將空白行去除: 搜尋目標以「^p^p」表示(記得不必勾「使用萬用字元(U)」)。一個「^p」表示一個換行符號,兩個「^p^p」就會空一行,所以將「^p^p」取代為「^p」,就可以將空白行去掉了。

其他還有許多用法請參閱reference。

 

Ref:

  1. Office產品支援中心: 尋找及取代文字或其他項目
Wednesday, September 01, 2010

(ORA-01031) Cannot create/edit view with the owner of the schema

environment: enterprise linux + oracle11gr2

前情提要:
userA先生在9i的時代運作得相當正常,當然包含本篇所要探討的小小新建一個view的動作。升級到11g之後某天,卻發現userA再也無法在自己的schema下create view... 這麼小小一件事情都辦不到!!! 檢查了權限也跟9i時代完全相同(就是CONNECT, RESOURCE, UNLIMITED TABLESPACE這麼簡單,所以也沒把腦筋動到權限上),なんで??? 當時為了應急直接用dba帳號幫他處理掉了,今天又遇到一次,該是要面對的時候了..

一開始看到的都是在說"物件的權限需要直接grant給指定的人,不要透過角色(ROLE)來做"這件事情,因為在所有stroe procedures或PL/SQL block裡,角色權限是不會起作用的(All roles are disabled inside stored procedures.)等,不過這並不是我的情況..

無意間看到這篇文章在探討Oracle的Role包含了那些權限,才恍然大悟...

9ir2的CONNECT角色裡包含了"CREATE VIEW"的權限,但在11g裡,CONNECT的角色卻只剩下"CREATE SESSION"的權限... 就這麼簡單... 所以在11g要另外把CREATE VIEW的權限grant給userA先生,這樣就可以正常新建/修改view了... 就這樣orz

若要詳細列出角色所包含的權限,可使用以下查詢:

SQL> select * from ROLE_SYS_PRIVS where role='CONNECT';
(ROLE_SYS_PRIVS: 列出登入帳號所有擁的角色,及角色所包含的系統權限)

或者也可以這樣查:

SQL> select * from DBA_SYS_PRIVS where grantee='CONNECT';
(DBA_SYS_PRIVS: 列出所有user/role所擁有的系統權限)

Tags