10.13.2011

Change Location

MOVE to new place , click here, here (blogger) will not update anymore!






搬家了 搬到這邊, 舊家不會更新了喔!

9.27.2010

Windows Live and WordPress

Now you can migrate your blog in windows live to wordpress.com...because they partnering toghter




現在Windows Live的Blog部分跟Wordpress合作了, 他有自動畫搬移的過程. 不過看起來account會變成以wordpress....嘖嘖嘖...

6.29.2010

GetLastError and FormatMessage and NewLine

When we use FormatMessage to get the system error message by the DWORD(from GetLastError), we will get a LPTSTR that end with NewLine (CRLF). How to convert to be NULL end string? It’s a very easy way to do it:

 

Code Snippet
  1. CString CGetInfo::GetError(void){
  2.     LPVOID lpMsgBuf;
  3.     DWORD dw = GetLastError();
  4.  
  5.     FormatMessage(
  6.         FORMAT_MESSAGE_ALLOCATE_BUFFER |
  7.         FORMAT_MESSAGE_FROM_SYSTEM |
  8.         FORMAT_MESSAGE_IGNORE_INSERTS,
  9.         NULL,
  10.         dw,
  11.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  12.         (LPTSTR) &lpMsgBuf,
  13.         0, NULL );
  14.     CString s = (LPTSTR)lpMsgBuf;
  15.     s.Remove('\r');
  16.     s.Remove('\n');
  17.     return s;
  18. }

當我們在用win32 API裡面的FormatMessage去處理GetLastError傳出來的DWORD 錯誤碼的時候, FormatMessage會回傳一個LPTSTR, 以\r\n結尾的字串, 那怎麼把那個\r\n去掉呢? 其實很簡單, 用CString.Rmove() 兩行輕鬆解決.

5.05.2010

FAST Admin Service

I am doing integration between FAST and Umbraco, and consider to decouple the FAST configuration and CMS environment.

Before go to do that I must find out a way to collect administration information from FAST. That is lucky that FAST do provide several web service to provide administration service.

It’s really simple to use the service. usually the admin service is locate at port 16089 and you can just reference the service as “http://host:16089/adminserver/servicename.jws”. and than you can use it as normal web service.

   1: FastAdminPresentationService.PresentationService ps = new FastAdminPresentationService.PresentationService();


   2: CredentialCache cc = new CredentialCache();


   3: cc.Add(new Uri("http:hostname:16089/adminserver/servicename.jws"),"Basic",new NetworkCredential("adminname", "adminpassword"));


   4: ps.Credentials = cc;




Following is the service I using and tested.



CollectionService.getCollectionNames <—get the collection names



IndexProfileService.getClusterNames() <—as name



IndexProfileService.getDeployedIndexProfile(ClusterName) <—get index profile xml



Get Search Profiles:





   1: FastAdminSearchProfilesService.SearchProfileRetrieveFilter filter = new FastAdminSearchProfilesService.SearchProfileRetrieveFilter();


   2: FastAdmiTest.FastAdminSearchProfilesService.SearchProfile[] list = sps.retrieveSearchProfiles(null, false, false, false);






Get the Navigators inside special Search Profile:



First, get the SearchProfile and keep the SearchProfile .publishedViewName, and then Reference PresentationService and get the navigator by publishedViewName as



Navigation navigation = ps.retrieveNavigation(the publishedViewName that we keeped);



Then, the navigation.navigators are what we want to have. If you want the list the same with the Admin Site UI showing, choice the navigators with blocked property be false.

4.23.2010

Microsoft Officie 2010 does not support upgrading from a prerelease version of Microsoft Office 2010.

Remember remove Send a smile” before install Office 2010 RTM if you join the Microsoft Connect Office 2010 program. else, you will get this error message:

Setup is unable to proceed due to the following error(s):
Microsoft Officie 2010 does not support upgrading from a prerelease version of Microsoft Office 2010.  You must first uninstall any prerelease versions of Microsoft Office 2010 products and associated technologies.
Correct the issue(s) listed above and re-run setup.

3.28.2010

[Umbraco] How to get media URL

Here is one way to do:

string s = string.Empty;
System.Xml.XPath.XPathNavigator n = umbraco.library.GetMedia(m.Id, false).Current;
System.Xml.XPath.XPathNavigator d = n.SelectSingleNode("/node/data[@alias='umbracoFile']");
s=d.InnerXml; // Here is the path

3.16.2010

.NET 4.0 Serializing IDictionary

Yes, now we can serializing the object which contain or implement of IDictionay in .NET 4.0.

The different part of code is change to using System.Xaml namespace and the code is more simple, for instance:

using (StreamWriter stream = newStreamWriter("C:\\data.xml")) {
    stream.Write(
XamlServices.Save(data));
}

Now the I have to reconsider the power of the web service…

 

現在我們可以在.NET4.0 的程式碼中Serializing(序列化)含有IDictionary或是繼承自他的物件.

差異的地方是我們必須引用System.Xaml, 新的序列化服務的寫法也變簡單了, 請參考下面程式碼:

using (StreamWriter stream = newStreamWriter("C:\\data.xml")) {
    stream.Write(
XamlServices.Save(data));
}

嘖嘖嘖..我現在要好好想想web service的威力了….

3.08.2010

System.Net.WebException: The request failed with HTTP status 503: Service Unavailable

Background:

  1. ASP.NET application (Web from or call another ASP.NET web service) in IIS6
  2. Complicated network environment
  3. Several web front ends
  4. Every web service call return 503…

Maybe you can try to setup the Internet Explorer proxy settings to bypass every web front end, and also downgrade the IIS from Kerberos to NTLM, and try it again.

Internet Explorer configuration :

  1. Tools –> Internet Options
  2. Connections Tab –> LAN Settings
  3. “Advanced” button inside “Proxy Server” group
  4. Add the web front ends’ domain name into the “Exceptions”

How to downgrade from Kerberos to NTLM:

  1. Open command prompt
  2. Change directory to “C:\Inetpub\Adminscripts
  3. Input:
    cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "NTLM"
  4. About WebSite, it is web site id, you can find it by fowllowing steps:
    1. Open Internet Information Services (IIS) Manager
    2. Click “Web Sites”, and you can found the value in the Identifier column
  5. Input as following command then you can rollback to Kerberos:
    cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "Negotiate,NTLM"

 

狀況:

  1. ASP.NET 應用程式呼叫ASP.NET web service, IIS6
  2. 網路環境有點複雜, 而且離我超遠
  3. 很多台web front end
  4. 隨便Call web service都回你503

我後來是這樣解的, 先把所有的web front end server都列入直接連線的部分, 接下來再把所有的web front end的IIS通通設定成NTLM. 先求可以通, 這樣回到Kerberos才有機會跟網管那邊確認問題.

怎麼設定bypass proxy server

  1. 打開IE, 工具->網際網路選項
  2. “連線” 那個頁籤, 選區域網路設定
  3. 按那個進階的按鈕
  4. 在那個例外裡面輸入web front end server的domain name

怎麼將IIS的Authentication設定成NTLM

  1. 打開”命令提示字元”
  2. 將路徑轉換到 “C:\Inetpub\Adminscripts
  3. 輸入:
    cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "NTLM"
  4. 那個WebSite就是站台的ID, 要找的話打開IIS管理工具, 然後點站台, 右邊就會有欄位顯示出來了
  5. 要倒回去Kerberos, 輸入下列命令即可:
    cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "Negotiate,NTLM"

2.26.2010

Visual Studio 2010 and 64x

The Redmond company is sticking with a 32-bit exclusive strategy for Visual Studio, at least for the time being, even though it is well aware that 64-bit architectures are becoming mainstream. <----sigh

 

這家位在Redmond的公司在Visual Studio上將繼續維持32-bit only的策略, 就算64-bit看來一定會是市場的主流. (link點上面那一個) <-- 嘆

1.31.2010

UNC and HttpContext.Current.User

If your ASP.NET web site running in a UNC location, and also running the site with windows integrated authentication.

And now, you are trying to get the Http.Current.User. You will get the account who running for Application pool whatever you login for test. I found the only way to get real login account is using Request.ServerVariables[“LOGON_USER”].

Environment: IIS6.0, Umbraco

Does anyone have another solution?

Remove Server From MOSS Farm

There are four way to remove the server from MOSS server farm.

  • First one is disconnect by running the configuration wizard from the start menu. This is the same way to use if you want to leave MOSS 2007 installed on the server but disjoined from the farm.
  • Second on is removes the server if you want to clean up the serer when it can contact the configuration database. This method also uninstalls the SharePoint from the server.
    • ​Use Add/Remove Programs in the control panel.
    • In "Add/Remove Programs", you can remove "Microsoft Office SharePoint 2007", and it wills pop-up a warning, Click Ok to continue.
  • The third method is removing the server from the server farm in the SharePoint Central Administration site. This way is easy and quickly, almost no latency, the action was completed. But this way don’t disconnect the server from the SharePoint database.
  • The last method is more advanced, it will disconnecting the server from the SharePoint configuration database. And then you can format the server or re-install MOSS, whatever you want for the server. The step is very easy:
    • Open a command prompt to c:\program files\common files\Microsoft shared\web server extensions\12\bin (the SharePoint installed path)
    • Run following command:
      psconfig –cmd configdb –disconnect

Actually, I do server remove by the three and last one method, remove the server from MOSS farm by Central administration site, and then disconnected the server from configuration database. It is easy and cleanly, and without reset anything/reboot machine.

8.19.2009

Runas in the machine don’t join domain

My laptop don’t join the company domain. Sometime I want to run a application as my domain account in the company domain to access the resource in the company domain, but the menu only existing “Run as administrator” when I right click the shortcut of the application.
How to resolve this?

There are two way I using to do Run As. One is ShellRunas v1.01, here is the detail description from Norm.

Another one is runas command in command prompt. Here is the syntax:

runas [{/profile|/noprofile}] [/env] [/netonly] [/smartcard] [/showtrustlevels] [/trustlevel] /user:UserAccountName program

It will easy to run the application as the account you have password.

If you encounter error by the command, please check do you accessed the machine by the account before first. That is because some program (as Visual Studio) running with account profile/env.

Change the connection string at runtime

I am doing a new project which try to utilize Quartz.Net to schedule the change of content base on Spring.Net and nHibernate.

The simple map is we have a regular process to deal with user’s request to change the content in the authoring environment and also input a schedule job into database by Quartz.Net. Another process, based on Windows Service will check the jobs queue, if the job startup time is up, then the process will update the content in the publish environment.

Seems the function is easy to implement. But we are frustrating for the timer job process to change database connection since the service module was based on Spring.Net and NHibernate.

After do some research and study, we finally found the solution to change connection string at runtime. (Beside this, actually there has another way to implement this function, by dual database provider).

This discussion thread detail the function implementation, and here is a great sample.

7.28.2009

About SPLimitedWebPartManager

Usually we add/update/delete web parts in the publishing page in MOSS 2007 by SPLimitedWebPartManager in object module. Most of the time, we got the test/demo small console program, then we implemented into QA/Staging/Production environment and got the expected result. But sometime not, and will confused us for a long time…

Recently, I am trying to add web part by object model, I choice the way to create web part instance and add the web part into PublishingPage by SPLimitedWebPartManager. The reason is the web part adding execute dll (thread) will called by the web part. So the only way to create new web part instance is by Reflection.

But I always got error message told me the page don’t check out? why? I run Page.Checkout() several time, and the web part adding was not work still. The error message is
The file is not checked out, You must first check out this document before making changes. at Microsoft.SharePoint.Library.SPRequestInternalClass.AddWebPart

After two weeks,  finally I got the hint in this discussion thread. Yes, the point is
PLEASE INITIAL SPLimitedWebPartManager AFTER Page Checkout.

7.24.2009

SharePoint June Cumulative Update Packages

Here is the announcement of Microsoft SharePoint Team Blog.

Build Number is 12.0.6510.5003.

Following are my note on this CU:

  1. The MSP_WEB_SP_QRY_ReadStatusApprovalHistory stored procedure takes a long time in some cases. – > Does this one meaning It will take a long time to process when we try to get the approval history?
    Beside this one is belong to MOSS 2007, others are for SharePoint Service 3.0.
  2. When a list is broken in your site, you cannot start a crawl successfully, and you receive the following error message in the crawler log:
    Crawling fails with "List does not exist" error Indexing and crawling failed with the following error: Crawling failed with an error for this URL: Error 0x81020026 The SharePoint list pointed to by this URL does not exist. Verify that it can be accessed using an internet browser. (List does not exist The page you selected contains a list that does not exist. It may have been deleted by another user.)
    However, you cannot delete the broken list by using the stsadm -o forcedeletelist -url http://servername:port/sites/sitename/listname command.
  3. SPList.GetItems(SPQuery) fails when the item count reaches the threshold value 2000, and you will receive the following error message:
    Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
  4. You configure a SharePoint server to accept incoming E-mail messages. You notice that incoming E-mail messages are processed based on their alphabetical order in the Drop folder. However, you want the incoming E-mail messages to be processed according to their order of creation in the Drop folder.
  5. Search query summary results are not rendered correctly when they contain Hexadecimal escaped characters. For example, a hexadecimal escaped character is displayed as "á".
  6. You have a SharePoint document library with the Major and Minor Version History option enabled. You also set the Only users who can edit items should see draft items option to "Who should see draft items in this document library?". If you use the "Get document" RPC method to download the drafts programmatically, it does not return the Draft Version.
    As a site administrator, when you use "Managed checked out files" to take ownership of documents checked out by other users in a Document Library that has 9 or more datetime columns, you receive the following message:
    Some of the files cannot be checked out by you. They have been deleted or checked in by other users.
    If you select more than one file to assume ownership, you notice that the operation succeeds only for the first file.
  7. You create immediate alerts and scheduled alerts on document libraries at the library level. You receive an initial E-mail indicates that a message alert is created. However, you cannot receive alerts for all the documents. This issue occurs in Contributor and Reader when major and minor versioning is enabled on the document library.
  8. You install the Hotfix package described in KB 968850. However, when you click Site Action in a SharePoint site, the menu in the Site Action is expanded to the same width as the Web page.
  9. You can display pictures from E-mail messages in an E-mail enabled "Discussion board". However, if users reply to your E-mail and insert pictures, the pictures from the replied E-mail message are displayed as "X" in the Discussion Board.
  10. Incremental content deployment from a source Microsoft Office SharePoint Sever (MOSS) 2007 farm to a target MOSS 2007 farm fails intermittently with SQL deadlock errors.
  11. In SharePoint document libraries that have versioning enabled, if you upload a new document and enter text in the Version Comments text box, the text you entered in the Version Comments text box will be lost, and will not be visible when you view the version history of the document.
    In the issue tracking list, you can open and save an attachment successfully for the first time, but when you try to save the attachment again, you receive the following error message:
    The Internet Address <URL> is not valid.
    About this one, the good thing is I never suggested user to use this list template.
  12. You use multi-value lookup values in a SharePoint list. However, you notice that some documents in the SharePoint list are unpublished. The multiple value lookup values in the AllUserDataJunctions table are still present and flagged as current version documents and are not marked to be deleted. Therefore, multiple value lookup values become orphans. In this case, if you use the stsadm -o export command, the export phase of the content deployment will fail.
    NOTED: LOOKUP COLUMN MAYBE CAUSED THE EXPORT FAILED IN PRE-VISION.
  13. When you edit a detached page in the pages library and then click Modify Shared Web Part, you are redirected to a "This page has been modified since you opened it" page.
    I think this error message was familiar for any SharePoint admin. m….maybe I have to check does this error message will popup again when I modified the navigation.
  14. You experience poor performance when you use the stsadm -o export command to export large sites.
    If possible, maybe some benchmark will help SharePoint admin more.
  15. If you rename a .doc file in the Document Library, the custom non-text properties of the .doc file change to a text type and lose their values. The custom properties are only created in the .doc file and there are no custom columns for the properties in the Document Library.
  16. When a SharePoint user creates a circular loop between lookup columns, if you click one of the lists that contain lookup columns, this action will cause 100% CPU usage on the SharePoint server. To work around this issue, you have to perform an application pool recycle.
    Ah…Ever loop, maybe add a condition check and popup a warning will be more help…whatever SharePoint was for the common user, right?
  17. When you restore a host header site collection from a backup to a new host header site collection, the host header value in the restored site collection is still the host header of the old site. After you restore the site collection, if you detach and reattach the content database of the restored site collection, the restored site collection is no longer available and will be left orphan.
  18. You use the Group By option in the People and Groups list, and then you set the group to "Collapsed by default". However, when you try to expand the group, it cannot be expanded.
  19. You move a sub-site to a new location, and then you delete its earlier parent site. In this case, the incremental deployment job fails, and your receive the following error message:
    Error deleting Web site "/ParentSite/SubSite". You can't delete a site that has subsites.
    You use a computer that is running Windows Vista in a domain that has an "&" in its NetBIOS domain name. When you try to use this computer to checkin a document into a SharePoint document, you receive the following error message:
    This document was checked out to your local drafts folder but the local copy could not be checked in to the site. Close any application that is editing the document and try to check in again, or discard the checkout.
  20. When you try to upload a .mht file generated by a third-party application to a SharePoint document library, you receive the following error message:
    No "boundary" in CGI environment.
    Troubleshoot issues with Windows SharePoint Services.
  21. Workflows do not recognize users from the Membership Provider in the SharePoint Designer when Forms-based Authentication (FBA) is enabled.
  22. You have a SharePoint list that has more than 500 items. The list has a column of "People and Groups" type with the "Allow multiple selections" setting set to "Yes". If you click Show Filter Choices in this list, you receive the following error message:
    #RENDER FAILED
  23. In an extranet deployment scenario in SharePoint, the URLs to access SharePoint internally and the URLs to access SharePoint externally are different. You access the SharePoint externally, you visit a page that contains a list view Web part, you edit the list view Web part, and then you click the Edit current view link. However, when you click Cancel to go back to the previous page, you receive a "file not found" error message. Additionally, when you examine the URL in the Internet Explorer address bar, it displays an internal URL.
  24. When you are using reusable content and perform a content deployment, only one version of the reusable content is preserved on the target site. It will always be the latest version on the source site regardless of whether the latest version is approved or not.

4.15.2009

The EventHandler Can't Update Item Data

This story has two part, one is SPItem, another is update failure.
When we update the SPItem property (Field Value) in EventHandler, we know we have to update the data in the event ItemUpdated and not in ItemUpdating. I believe it is easy to find the reference in the www.

We also know we can't utilize the parameter value directly in the ItemUpdated function, we have to initial different instance from new SPSite, SPWeb by the information from patameter, and then we can utilize SPSecurity.RunWithElevatedPrivileges. But in this case, we also have to update property in the difference instance. Why? basically that just my experiences, sometimes the parameter instance will be null when the event handler triggered. Why said sometime? That's also I wonder to understand, in the many many test, I can't figure out why sometime the parameter instance is null. If anyone know the RC, please kindly enlighten me.

But even those, sometimes the instance created by us also be null. Why? I guess that is the latency of the event handler. The following is what I do for it:
SPListItem temp = null;
while (temp == null) {
Thread.Sleep(500);
temp = properties.OpenWeb().Lists[properties.ListId].Folders.GetItemById(properties.ListItemId);
}
Yes, I just sleep the thread..

This really resolve my case for half year, but before couple days, this trick don't work.
After check with MSDN, Here is the Final version.


RETRY2:
int retrycount = 0;
try {
SPListItem temp = null;
while (temp == null) {
Thread.Sleep(500);
temp = properties.OpenWeb().Lists[properties.ListId].Folders.GetItemById(properties.ListItemId);
}
temp[_TSSDocumentFieldName] = url;
temp.Update();

//UPDATE.....
} catch (Exception ex) {
retrycount += 1;
if (retrycount <= 5) {
System.Threading.Thread.Sleep(2500);
goto RETRY2;
} else {
debug.Append("[EXCEPTION][UPDATE PATH 2]" + ex.ToString());
throw ex;
}
} finally {
this.EnableEventFiring();
}
}
}

mm.....actually I am shocked when I saw the sample code in MSDN document.

3.21.2009

How we can add comment into folder in the document library of SharePoint

The document library in SharePoint 2007 is good for sharing information, but sometimes people want to add some comments into the folder. How to do it?

It’s very easy to do it by configuration. First, we have to define a new Content Type which inherit from folder type. And then we can change the document library to be able to contain multiple content type, and add the new content type we just created into the document library.

So, here is the steps:

Click Site Action –> Modify All Site Settings into the Site Setting Page.

Click Site content types which under Galleries column.

Click Create in the Site Content Type Gallery.

Key in Name and Description, Select Folder Content Types as parent content type group and select Folder as parent content type.
Note: The content in the description will be shown as image below, after all steps are completed.


After the content type is created, we can go back to the document library, and click Settings –> Document Library Settings. And select Advanced Settings under General Settings column.


Change Allow management of content types? to be Yes, and change Display “New Folder” command on the new menu? to be No.

Go back to the document library settings page and click Add from existing site content type.

Add the content type that we just created.

Now we have two content types in this document library, and then we have to create the comment column for the folder content type. Click Add from existing site column in the Columns section. Add the column called Comments, uncheck “Add to all content type”.
After the new column is added, we also have to add the column into the content type. Click the content type we just created, in this case, it’s “New Folder Type”. Click Add from existing site or list columns, select columns from List Columns and add the column we just added.
Now, it’s done, we can try a new “Folder Content Type” and edit the property “Comments”.


Change the content type to “New Folder Type”

Then you can comment your folder

1.13.2009

About PropertiesBag

最近都在忙有關MOSS的開發, 遇到一個狀況. 就是說當我開發一些SharePoint上面的應用程式時 當然會遇到要儲存資料的狀況. 一般來說 我們會把資料盡量放在SharePoint的List中. 但是如果是一些Configuration呢?

因為大部分是簡單的資料, 所以後來的做法是放到Web Site的PropertiesBag, 單純的Key Value Pair, 相對很方便.

不過後來就是因為這個所以有痛到, 因為系統有跑Content Deployment, 所以會把資料從開發環境送到正式環境. 是的, 正如你想像, PropertiesBag會蓋過去. 這下子就死定了.

所以這告訴我們, 當有Content Deployment時, 很多東西的處理上要改變一下.

 

Recently I am busy with some application development on SharePoint. Here is a usual case for the development, there always have some data have to stored, most of them are simple value, as configuration.

In the first, we stored it in SharePoint List or PropertiesBag.Seems good, right? Everything is good until deploy to another server farm. The propertiesBag will copy in content deployment! oh….My database connection, web site id…etc….

This is the lesson, we must change the view when we are utilize SharePoint content deployment