Tuesday, June 1, 2010

How to update file / list item without harming the metadata & some more tips...

Nice thing I came across with the other day -

If you need to modify some SPListItem fields in lists, but you want to keep the "modified by" or "Last modified by" as it were before you can just use the method SystemUpdate ( which is exactly like Update but without changing those fields ).

 
using (SPSite site = new SPSite("http://blah-blah.com"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["ListName"];
foreach(SPListItem item in list.Items)
{

item["Title"] = "*changed*";
item.SystemUpdate();
}
}
}

Another cool thing is :

You have two different "last modified" for a SPListItem. What do I mean by that ? you have the SPListItem["Last Modified"] value and you have also under SPListItem.File.TimeLastModified. In other words, you can see when the file that corresponds with that item were last used and not assuming that date from the "last modified" value that you have in the list.

 
public DateTime TimeLastModified { get; }


Last cool thing, promise , for this post :

When you want to upload a file to a list ( adding it to a file collection of that list ) you can you use a really strong overload under SPFileCollection -
 

public SPFile Add (
string urlOfFile,
Stream stream,
SPUser createdBy,
SPUser modifiedBy,
DateTime timeCreated,
DateTime timeLastModified
)


With this overload you determine what will be the createdBy,modifiedBy,timeCreated,timeLast modified...

This is very useful when you need to download/upload files from/to you SharePoint sites ( dont forget of course to backup metadata before using that so you will be able to retrieve it back :) )

Sunday, May 2, 2010

How to work with SPList the best way - Work with GUIDs!

Sometimes you develop some SharePoint application that needs to modify/change data in Lists/Doclibs.
Sometimes you being lazy and just use the title/display name of the field ( SPList.Fields["Title"] ) option in order to get the right field you want to work on.
So sometimes you are being wrong.

Even though it will work great, it won't work in any language.

2 options you have then - Internal name ( which usually will be enough but problematic when it comes for columns with similar name, such as "Modified" and "Modified By" ) or GUIDs ( because the OOB fields have const guids for any list ).

So just have a look on that and start working better ( and support any language ).

Internal Name :

Created By : Author
Modified : Modified
Modified By : Editor
Has Copy Destinations : _HasCopyDestinations
Copy Source : _CopySource
Approval Status : _ModerationStatus
Approver Comments : _ModerationComments
URL Path : FileRef
Path : FileDirRef
Modified : Last_x0020_Modified
Created : Created_x0020_Date
File Size : File_x0020_Size
Item Type : FSObjType
Effective Permissions Mask : PermMask
ID of the User who has the item Checked Out : CheckedOutUserI
Is Checked out to local : IsCheckedoutToLocal
Checked Out To : CheckoutUser
Name : FileLeafRef
Unique Id : UniqueId
ProgId : ProgId
ScopeId : ScopeId
Virus Status : VirusStatus
Checked Out To : CheckedOutTitle
Check In Comment : _CheckinComment
Checked Out To : LinkCheckedOutTitle
Document Modified By : Modified_x0020_By
Document Created By : Created_x0020_By
File Type : File_x0020_Type
HTML File Type : HTML_x0020_File_x0020_Type
Source Url : _SourceUrl
Shared File Index : _SharedFileIndex
Edit Menu Table Start : _EditMenuTableStart
Edit Menu Table End : _EditMenuTableEnd
Name : LinkFilenameNoMenu
Name : LinkFilename
Type : DocIcon
Server Relative URL : ServerUrl
Encoded Absolute URL : EncodedAbsUrl
Name : BaseName
File Size : FileSizeDisplay
Property Bag : MetaInfo
Level : _Level
Is Current Version : _IsCurrentVersion
Select : SelectTitle
Select : SelectFilename
Edit : Edit
owshiddenversion : owshiddenversion
UI Version : _UIVersion
Version : _UIVersionString
Instance ID : InstanceID
Order : Order
GUID : GUID
Workflow Version : WorkflowVersion
Workflow Instance ID : WorkflowInstanceID
Source Version (Converted Document) : ParentVersionString
Source Name (Converted Document) : ParentLeafName
Title : Title
Template Link : TemplateUrl
Html File Link : xd_ProgID
Is Signed : xd_Signature
Merge : Combine
Relink : RepairDocument

GUIDs :

ID : 1d22ea11-1e32-424e-89ab-9fedbadb6ce1
Content Type ID : 03e45e84-1992-4d42-9116-26f756012634
Content Type : c042a256-787d-4a6f-8a8a-cf6ab767f12d
Created : 8c06beca-0777-48f7-91c7-6da68bc07b69
Created By : 1df5e554-ec7e-46a6-901d-d85a3881cb18
Modified : 28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f
Modified By : d31655d1-1d5b-4511-95a1-7a09e9b75bf2
Has Copy Destinations : 26d0756c-986a-48a7-af35-bf18ab85ff4a
Copy Source : 6b4e226d-3d88-4a36-808d-a129bf52bccf
Approval Status : fdc3b2ed-5bf2-4835-a4bc-b885f3396a61
Approver Comments : 34ad21eb-75bd-4544-8c73-0e08330291fe
URL Path : 94f89715-e097-4e8b-ba79-ea02aa8b7adb
Path : 56605df6-8fa1-47e4-a04c-5b384d59609f
Modified : 173f76c8-aebd-446a-9bc9-769a2bd2c18f
Created : 998b5cff-4a35-47a7-92f3-3914aa6aa4a2
File Size : 8fca95c0-9b7d-456f-8dae-b41ee2728b85
Item Type : 30bb605f-5bae-48fe-b4e3-1f81d9772af9
Effective Permissions Mask : ba3c27ee-4791-4867-8821-ff99000bac98
ID of the User who has the item Checked Out : a7b731a3-1df1-4d74-a5c6-e2efba617ae2
Is Checked out to local : cfaabd0f-bdbd-4bc2-b375-1e779e2cad08
Checked Out To : 3881510a-4e4a-4ee8-b102-8ee8e2d0dd4b
Name : 8553196d-ec8d-4564-9861-3dbe931050c8
Unique Id : 4b7403de-8d94-43e8-9f0f-137a3e298126
ProgId : c5c4b81c-f1d9-4b43-a6a2-090df32ebb68
ScopeId : dddd2420-b270-4735-93b5-92b713d0944d
Virus Status : 4a389cb9-54dd-4287-a71a-90ff362028bc
Checked Out To : 9d4adc35-7cc8-498c-8424-ee5fd541e43a
Check In Comment : 58014f77-5463-437b-ab67-eec79532da67
Checked Out To : e2a15dfd-6ab8-4aec-91ab-02f6b64045b0
Document Modified By : 822c78e3-1ea9-4943-b449-57863ad33ca9
Document Created By : 4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb
File Type : 39360f11-34cf-4356-9945-25c44e68dade
HTML File Type : 0c5e0085-eb30-494b-9cdd-ece1d3c649a2
Source Url : c63a459d-54ba-4ab7-933a-dcf1c6fadec2
Shared File Index : 034998e9-bf1c-4288-bbbd-00eacfc64410
Edit Menu Table Start : 3c6303be-e21f-4366-80d7-d6d0a3b22c7a
Edit Menu Table End : 2ea78cef-1bf9-4019-960a-02c41636cb47
Name : 9d30f126-ba48-446b-b8f9-83745f322ebe
Name : 5cc6dc79-3710-4374-b433-61cb4a686c12
Type : 081c6e4c-5c14-4f20-b23e-1a71ceb6a67c
Server Relative URL : 105f76ce-724a-4bba-aece-f81f2fce58f5
Encoded Absolute URL : 7177cfc7-f399-4d4d-905d-37dd51bc90bf
Name : 7615464b-559e-4302-b8e2-8f440b913101
File Size : 78a07ba4-bda8-4357-9e0f-580d64487583
Property Bag : 687c7f94-686a-42d3-9b67-2782eac4b4f8
Level : 43bdd51b-3c5b-4e78-90a8-fb2087f71e70
Is Current Version : c101c3e7-122d-4d4d-bc34-58e94a38c816
Select : b1f7969b-ea65-42e1-8b54-b588292635f2
Select : 5f47e085-2150-41dc-b661-442f3027f552
Edit : 503f1caa-358e-4918-9094-4a2cdc4bc034
owshiddenversion : d4e44a66-ee3a-4d02-88c9-4ec5ff3f4cd5
UI Version : 7841bf41-43d0-4434-9f50-a673baef7631
Version : dce8262a-3ae9-45aa-aab4-83bd75fb738a
Instance ID : 50a54da4-1528-4e67-954a-e2d24f1e9efb
Order : ca4addac-796f-4b23-b093-d2a3f65c0774
GUID : ae069f25-3ac2-4256-b9c3-15dbc15da0e0
Workflow Version : f1e020bc-ba26-443f-bf2f-b68715017bbc
Workflow Instance ID : de8beacf-5505-47cd-80a6-aa44e7ffe2f4
Source Version (Converted Document) : bc1a8efb-0f4c-49f8-a38f-7fe22af3d3e0
Source Name (Converted Document) : 774eab3a-855f-4a34-99da-69dc21043bec
Title : fa564e0f-0c70-4ab9-b863-0177e6ddd247
Template Link : 4b1bf6c6-4f39-45ac-acd5-16fe7a214e5e
Html File Link : cd1ecb9f-dd4e-4f29-ab9e-e9ff40048d64
Is Signed : fbf29b2d-cae5-49aa-8e0a-29955b540122
Merge : e52012a0-51eb-4c0c-8dfb-9b8a0ebedcb6
Relink : 5d36727b-bcb2-47d2-a231-1f0bc63b7439

Monday, April 12, 2010

Content DB grows but site collections size are not, how come ? EventCache table !

Ok - Imagine this scenario. Your content DB is growing, but no new data is getting into your sites. How come ? a Bug.

If you still haven't installed your SP2 to your Moss farm , you are might meeting this deal. Each operation is written to that table, and need to be deleted after a certain amount of time by the timer job. But the bug is that it doesnt delete those old records in the table, and it just getting bigger and bigger...

So what you can do now is install SP2 or if it's not feasible now, you can do this method :

Use the SQL management studio. Go to your content DB and run the Store procedure named - "proc_DeleteChanges".

It gets two parameters ( both are integer ). One is for how many days to keep the changes and the second for how many days to keep events. So just put in the last month ( the number 30 as 30 days ) and execute it.

Things to notice before - while this operation run, your log might grow very much ( make sure you have enough disk space and might take a few hours depends on your DB size ).

Afterwards just make a re-organize pages before releasing unused space, and you got yourself the normal size of the content DB as it should be.

Of course do it before on a non-production environment.

Good Luck.

Tuesday, March 9, 2010

Failed to upgrade SharePoint Products and Technologies - PostSetupConfigurationTaskException

Grr.

A really annoying exception I had while trying to upgrade one of my Moss farms Im working on. The thing is, that I haven't experienced this error in any of the other farms I upgraded before.

What's happened ? I installed the sp2 successfully. Then ran the Configuration Wizard, and In the step 3 out of 4 got this very odd exception :

Failed to upgrade SharePoint Products and Technologies. An exception of type Microsoft.SharePoint.PostSetupConfiguration.PostSetupConfigurationTaskException was thrown.

As you can see it doesn't give you too much of a details. I started to google this issue and came across with a post about this exception.
In that post, it was suggested to stop the World Wide Publishing service of the IIS and to stop all the Sharepoint services you have working on that server ( i.e "Windows SharePoint Services Web Application" and etc ). And only then run the configuration wizard, and then restart the services.

In the first server, I did it this way and it worked like a charm.
On the rest of the servers, I checked it and decided to stop only the "Windows SharePoint Services Web Application" and not any of the IIS services or other Sharepoint services - Because of the long recovery time it took. That worked too. )


So my recommendation to you is just to stop the
" Windows SharePoint Services Web Application"
service. and save yourself the time of stopping all the other services which seems to be unnecessary to be stopped.

Be aware, when you stop that service, all web applications you had on that server ( That you can see in the iis manager ) will be gone, but once you start the service again, it will automatically re-create them and it might take a while depends on how many web applications you have - Though, you should check that they were created well, especially if you don't deploy your solution as MS recommends.

Good Luck upgrading.

Sharepoint בעיה נפוצה בעת התקנת עדכון לחוות

שלום,

.sharepoint לאחרונה נתקלתי בשגיאה שעיכבה לי הפצה של עדכון לחוות

.למעשה, לא נתקלתי בסוגיה הנ"ל ברוב המקומות בהם הפצתי את העדכון , אלא רק במקום אחד

בעת הפצת עדכון לאחת הסביבות אצל הלקוח שלנו, בשלב הרצת האשף קיבלנו שגיאה בשלב השלישי

השגיאה הייתה -

Failed to upgrade SharePoint Products and Technologies. An exception of type Microsoft.SharePoint.PostSetupConfiguration.PostSetupConfigurationTaskException was thrown.

השגיאה למעשה לא ברורה ולא נותנת יותר מדי כיווני חקירה.

.הפתרון העוקף היה פשוט לעצור את אחד השירותים של השרת עצמו - שיוביל הפסקת אירוח האתרים עליו
Windows SharePoint Services Web Application גשו לאתר הניהול המרכזית והפסיקו את השירות שרץ על השרת.

לאחר מכן הריצו את האשף, ובסיומו הפעלת השירות מחדש, וכלל האתרים יחזרו להתארח על השרת הנ"ל.

.IIS אני בודק עכשיו אם אפשר להתמודד עם זה רק ע"י עצירת השירות של ה

.בהצלחה

Monday, March 8, 2010

How to uncheck the overwrite check box in Upload.aspx page ?

Hey.

Very common issue, that I was also asked to do over clients in past version of Sharepoint too.

Well, by default when you create a Doclib , in the upload.aspx page the "overwrite" checkbox is checked. The outcome is that people overwrites files by accident.

So how you uncheck this checkbox on all your doclibs ? Change it in the templates.

This is how -

in Wss 2.0 , go your sharepoint hive, under the TEMPLATE folder ( TEMPLATE\1033\SPSTOC\LISTS\DOCLIB ) - backup the Schema.xml file and change the follwing lines :
 




change the value to FALSE.

And then scroll a bit down and track down this line -
 




and delete the word CHECKED.

Now save the file, do an iisreset - and the upload.aspx page is done.

in Wss 3.0, it's even simplier because all of those pages are application pages.

Just go to the sharepoint hive ( 12\template\layouts ) , backup and open the upload.aspx file.
Track down this line -

 




and just change the "Checked" attribue to "false".

BE AWARE - on every hotfix/service pack you need to check that the file hasnt change. If it did, remember to fix it again.

Enjoy.

Sunday, January 31, 2010

והפעם גם בעברית

,שלום לכולם
,לאחר תקופה ארוכה בה כתבתי בלוג אך ורק באנגלית
.החלטתי להתחיל לשלב גם פוסטים בעברית על מנת ולנסות להתקדם בצורה יעילה יותר במנועי החיפוש
- בימים הקרובים אתחיל להעביר את הפוסטים מהבלוג הלועזי שלי לבלוג הנ"ל
,מקווה שתצליחו להפיק את המיטב מהבלוג
.בהצלחה לכולנו