Wednesday, December 1, 2010

CAML vs Linq : round two

A while ago I wrote a post about CAML And Linq when working on MOSS, that post was giving an example of what and when to use each one of them ( when you work on MOSS).

Since that post, a newer version of SharePoint came out, the 2010.
Which is definitely worth writing another part ( update ) for that post.

Actually, I should start with the end result, now you can use Linq in all cases and you will get same results ( only in SharePoint 2010 ).

Now, there is the - how come ? Answer : SPMetal.

What SPMetal does ? In a nut shell, creates an entity class that provide another layer in which your Linq code can access directly to the database ( content db ).
Which is in other words, give you the same performance you could only achieve with CAML queries.

So, if you work with SharePoint 2010 you can work with Linq always. You got my approval :)

Thursday, November 4, 2010

GridView value set to null when column is not visible

You made an Update method to take care of updating your gridview, but there are some columns that are not needed to be shown in the default gridview but you do need them in the update method.
Then, when you try to use those columns data in your method, you will see they have null even though they had value in them...

What can you do then ?

Write those column name in the DataKeyNames section of gridview control. Then, those columns will be available and not with null value in your update method.
 



Good luck.

Saturday, October 16, 2010

How to save scroll location after postback ?

There are two options for that - to implement it with javascript or server side.

The server side implementation is very simple, we will have to do a small change in the web.config file.

 





Be aware - more work on the server side, more memory being consumed. But this method is very quick to implement.

Good Luck.

Sunday, September 12, 2010

"FileNotFoundException was unhandled" SharePoint 2010 newbies error

היי,

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

בעת הרצת אפליקציית קונסול יש לוודא לאיזו פלטפורמה מגודרת האפליקציה. כברירת מחדל , אפילו על מכונת 64 ביט, הויז'ואל סטודיו מותאם לרוץ לפלטפורמה של 32 ביט. לכן בעת ריצה ושימוש בקלאסים של שרפוינט , אנחנו נעוף מהסיבה הפשוטה שהם מותאמים ל 64 ביט, אז ברגע שננסה להשתמש באובייקט ששייך לשרפוינט נעוף על השגיאה שבנושא.

הפתרון פשוט מאוד - לכו להגדרות הפרויקט/אפליקציה שלכם , ועדכנו תחת הגדרות הבנייה (build) שזה ירוץ על סביבת 64 ביט.

שימו לב, שרפוינט רץ היטב רק בדוט נט 3.5 אם תחליפו את הפרויקט שלכם ל4 ( למשל , בשביל להשתמש ביכולות יותר מתקדמות לרכיבי אופיס ) גם תקבלו תעופה.

בהצלחה.

"FileNotFoundException was unhandled" SharePoint 2010 newbies error

Hi,

Some error that I had just when I started working on the SharePoint 2010 machine. I tried to investigate the SharePoint 2010 API , but surprisingly even trying to create an SPSite object cause a runtime error.

The reason is that you Visual Studio is set for running a 32 bit application, and SharePoint 2010 is 64 bit of course.

The only thing you need to do is to go to the properties of your application/project, then change under the Build tab - the platform target to x64.

Now re-run your console application.

Done.

Tuesday, August 10, 2010

Unexpected Error - When attempting to check "User notifcations". BUG!

Hey,

Today I came across with a very annoying bug when you try to get into the "user notifications" under "site actions".

When you press that link you might get an "unexpected error" - with not much info in the event viewer, nothing if you change the custom errors to off ( in the web.config ). That made me read the Moss log and to see that im being thorwen away with THE famous error AKA "null object refernce".

This made me realize that from some odd reason I have nothing under this link or in other words its not initialized at all...

Then I made a subscription in that web site to some doclib and afterwards I was able to reach that page ( sub*.aspx , forgot the name :) ) and to see that info. Deleting my subscription made the page unavilable again.

So instead of checking if the site has any subscription at all and just prompt some more friendly message or letting you know that there is no subscription to the site -it throws you off with this unexpected error...

It always unexpected when you program wrong. Please check for Nulls.

Thanks.

**This issue was checked on a Moss farm with SP2 and Cumulative update June 2009

שגיאה בלתי צפויה - התראות משתמש

היי,


היום לצערי נתקלתי בעוד באג בפלטפורמה המופלאה שלנו...


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


לצערי לא היו לוגים רלוונטים ברמת השרת, לאחר שינוי ברמת האתר הוירטואלי לראות לוגים ע"י שינוי ה custom erros ברמת ה Web.config


בסופו של דבר נברתי בלוגים של המערכת וראיתי שאני עף על שגיאה של

"The object reference set to null"


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


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


מילות סיכום, אם אין מנויים באתר - אין אפשרות לראות "התראות משתמש"



תודה.

Wednesday, July 21, 2010

Access Denied and Content type - who changed PermMask ?

Hello,

I wrote about this issue a while ago , and back then I came across with some hotfix tha was released from MS.

Since I saw this error again a few weeks ago, and I tried to fix it with this small utility - It brought me to the conclusion that their solution is not good enough.

Why ? several reasons -

1. It fix only one list, so you can of course iterate via all lists in the sites. But it still won’t solve the issue for new lists in that siteCollection.
2. It doesn't solve the damage that was done in the site collection level.
3. Through their code , you can't really understand how it connects to content type at all.

So what really happened then ?

By editing the list or the site with some editor, the content type that represent the permission mask in any list/doclib might have damaged. That content type is being reproduced itself in any list, so any new lists in a infected site, will be with this error as well.

So how do you really fix it ? After fixing the all the infected lists, by fixing their schema ( adding the missing attribute ), you need to fix that content type in the site collection level. How to do that - fix the content type in SPSite.RootWeb.

To sum things up, each content type has a definition which include the fields of that content type.

one of the fields is missing and you already know what to add ( check the code in my older post ) - that simple, but thats not documented.

Hope now you know what you need to fix when you get an Access denied on every item when you try to edit it !

Good Luck!

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

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

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

Monday, January 4, 2010

Archive for sharepoint ? Hitachi is joining the Game...

Another Player joined the game.
I don't want to go around the bush, so I will just say it. It's not ready.

Why ?

1. Broken links. How come ? its leaves a stub ( link ) to the archived file, but the link is not the same name of the file ( FILE_NAME.html )

2. You have to add an appliance, it's not only a software, so if you have a DR solution, you will have to buy two of those.

3.You can't crawl the document itself with the Moss search engine.
And some more issues. I can't find my notes from the meeting. I will update it soon.

Saturday, January 2, 2010

Archive for Sharepoint ? Symantec Enterprise Vault... Round# 3

Finally. There is an archive product which is ready for archiving Moss.

Yes. They solved most of their issues. And I can proudly say that I saw this product developing progress since it early days.

Why it's ready ?
1. Supports Kerberos.
2. It is transperent to the end user. How come ? The list looks the same. The file name hasn't changed. It's only down sized to 1kb ( even less if you want to be accuarte ).
3. We can crawl it. Since they added the transperent mechanisim, the crawler just see it as regular file.
4. When you edit the file, or do any modification, or drag it to another list, it retreives it back from the repository to the list and bring it back to his original size.

Some small problems, that I still need to mention :
1. Doenst support item level premission ( but they have nice workaround ).
2. The policy mangement is not versital enough.
3. Not enough documentation. Capicity planning is not easy without it.