Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Archive for June 2009

Stsdev bug – unexpected error has occure

leave a comment »

Today I’ve created a new project for simple feature with use of stsdev tool. Creation went smoth without any problem. Then I open the visual studio 2008, added my project to the solution (as it was new project for bigger solution), did some codding and finally went for hitting F5 for the first time. Guess what happend:
 
 
woow ūüė¶
 
I started to dig and found that stsdev is rising exception:
 
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path ‘C:\MyProj\Lawyers\DeploymentFiles\SolutionConfig.xml’.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path)
   at stsdev.SolutionConfigBuilder.Create(String FilePath, Boolean AssemblyDeployment, Boolean SafeControlSettings, AssemblyDeploymentTarget DeploymentTarget, PermissionSet CasPermissions)
   at stsdev.SolutionConfigBuilder.Create(String FilePath, Boolean AssemblyDeployment, Boolean SafeControlSettings, AssemblyDeploymentTarget DeploymentTarget)
   at stsdev.SolutionConfigBuilder.Create(String FilePath, Boolean AssemblyDeployment, Boolean SafeControlSettings)
   at stsdev.SolutionConfigBuilder.Create(String FilePath, Boolean AssemblyDeployment)
   at stsdev.SolutionBuilder.LoadSolutionConfigFile()
   at stsdev.SolutionBuilder.RefreshDeploymentFiles()
   at stsdev.SolutionBuilder.RefreshDeploymentFiles(String TargetSolutionName, String TargetSolutionDirectory)
 
After digging for a while, I found reason of the problem. This was caused by the first line, when stsdev is call¬†with parameter "‘C:\MyProj\Lawyers\DeploymentFiles\SolutionConfig.xml’" which is wrong. I dig a little bit more and found that there is a problem with file "Microsoft.SharePoint.targets" located inside "DeploymentFiles" directory. This file is a configuration file for building your solution. If you open this file, you should find line like this one:
 

<REFRESH>$(STSDEV) /refresh "$(TargetName)" "$(SolutionDir)"</REFRESH>

Here is a small bug which you will see in case when your project is inside solution. In my case it is, so my "DeploymentFiles" directory can not be found by stsdev. To solve the problem you need to update above line to look like this:

<REFRESH>$(STSDEV) /refresh "$(TargetName)" "$(ProjectDir)"</REFRESH>

after that, just unload your project, go to explorer and remove "bin" and "obj" folder, reload project and try to build it. This time you should not get the error (at least I don’t)

 

Written by Mariusz Gorzoch

24 June 2009 at 15:02

Posted in SharePoint

Be carefull with “Save site as template”

leave a comment »

Few days ago I was fighting with creating custom template and later on trying to query all sites build based on that template. Sound easy as what you need to do is in the most simple way iterate thru all sites in your root web and just check what is the "TemplateID". Based on that you can browse/present for the user all sites build with use of particular template ID. So, what is tricky part ? The tricky part is that when you are using "Save site as template" functionality of SharePoint UI you will always get template ID equal to the template ID of template site used to as base for you site template. If you don’t change this ID somehow, then you will end up with quering not only sites build on your template, but also sites build on the parent template used for building your template.
 
 
the question is if we can do something about that ?
 
as you can imagine, of course we CAN !
 
When you save your "custom template" it goes with extension ".stp". This file is nothing else as "CAB" file, so we can get and dig into it. First, we need to extract it content to some dictionary. To do so, we can use "WinZip" (just change extension of the file to ".cab" and open it with "WinZip"). After extraction we should find there file with name : manifest.xml. Now you need to open this file in edit mode and look for the tag "<TemplateID>"
 
 
to change ID of the template you need to replace the current value inside <TemplateID></TemplateID> with your custom value. Personally I suggest to peak some value above 30000.
 
Now, save and exit.
 
Ok, we are almost done, now we need to pack our solution again back to .stp. To do this, we need to use "MakeCab" tool. Before we go and use it, we need to prepare script "ddf" file. This file is nothing else like a text file, which contain list of files to be packed inside "cab". In my case my orginal ".stp" file contain of 5 files:
 
– 53000000.000
– f2000000.000
– g2000000.000
– h2000000.000
– manifest.xml (this one was changed with new TemplateID)
 
All those files need to be puted in "ddf" file, where each one is placed in separete line.
 
if you done this, then now what you need to do is nothing else like call "MakeCab" to create our "cab" file. To do so we need to issue cmd: "MakeCab /F <our.ddf>". When you do this, you should get new directory in the place where you start the command with name "disk1". Go to this directory and you should find your cab file. Now you need to rename it to ".stp" and you are ready to go ! ! !
 
use stsadm -o addtemplate -filename <your stp file> -title <your template title>
 
and your template is back again in sharepoint. Now if you create some sites based on it, you can be sure that they will have their own new ID, choisen by you during editing "manifest.xml" file.
 

Written by Mariusz Gorzoch

22 June 2009 at 21:05

Posted in SharePoint

Dear TFS why you reject my connection?

leave a comment »

It happend for me for the sixth time and now I decided to write this down, so I’ll not have to look for it again, when this problem hit me in the future again (and it will… I know the Murphy law). So what is the problem ? Did you ever established your brand new development enviroment on completly clean machine¬†! installed visual studio¬†! added Team explorer to it¬†! then, finally after 12 hours tried to connect to your corporate Team Fundation Server and bang, you get this criptic error message:
 
 
I did, and today it is at least 6th time when I hit the wall!
Now you started to think, what is the reason of the problem, and hire I puted some hints what it can be and what solve my problem each time when I get it:
 
1. DNS problem. Check if the machine from where you connecting can recoginze your corporate TFS server by name. As you know or not, even if you provide IP address of TFS, then Team explorer will connect to TFS and in response get redirection to the same server but this time, by name. If you station can not recoginze server by his DNS name, then you will stuck! How to solve this ? if you are not DNS admin and you just can not add your machine there, then you can go and use "host" file located at : "C:\WINDOWS\system32\drivers\etc". This is text file, where you can put IP address and then DNS name. Windows will use this file to resolve IP into DNS name.
 
2. Who am I?. This maybe sound strange, but this is the reason of secound problem I usually have. When you connecting to TFS you need to provide somehow creadenatils. And now is ticky question : what credential Team explorer will provide to your corporate TFS if there is no setting to set them up ? This is quite easy: he will provide credentials of currently logged users and if you are the "administrator" (developers are allways administrator on they dev stations :)), then you for sure stuck, as I don’t believe that password for your local administrator will match the one for TFS :). I hope that this thing Microsoft Visual Studio team will correct in the next version, so I’ll have option to provide not only server name, but also creadenatials to use. Anyway to overcome this problem I’m using component from "control panel" : "Control panel->Stored user names and passowrds". If you open this adding then he will show you the list of currently remembered logins for remote servers:
 
 
this component let you define login/password which this machine should use when connecting to remote server. As you can understand we will use this to tell windows to use special creadenatials when accessing our corporate TFS.
 
 
and when you put the credentials hit "Ok" button:
 
 
now you just need to "close" this window, restart you visual studio and try connect to TFS again. This time it should work ūüôā
 

Written by Mariusz Gorzoch

16 June 2009 at 22:04

Posted in TFS

Becoming a sharepoint developer

leave a comment »

When I started my path of upgrading my skills to work with SharePoint I didn’t know what exacly this¬†SharePoint is about. Now after a while I think I get some experiences and I think that I understand this better. Today I watch quite good¬†panel session done on TechEd 2009 by SharePoint MVPs¬†which summarizes my thought¬†(if you have access to techEd online, you can find it hire). Bellow you can find few hints I would like to find when I was on the begginig of this path. Hope that they let you better understand what SharePoint is and how to handle it, when starting from asp.net developer position:
 
1. On the first place I decided to put : think forward. When you developing application for sharepoint you need to think about entire application lifecycle. Not only about development but also about deployment, upgrading and removing of your solution from the deployment enviroment. SharePoint is an platform and it can contain thousands solution like yours. You should play nicely as if you will not, then you find quickly that you need to rebuild your entire farm and start around from the beggining.
 
2. Knowledge comes with experience. Do not give up on the beggining. During becoming SharePoint developer you need to understand each pice of SP framework (like content types, lists, libraries, site colument, sites, ect) and deeply understand how to play with each of them (how to add them, upgrade and remove). In general it takes around 1 year for the asp.net developer to jump into SharePoint and start to look around. Keep this in mind, you can get experience but it requires some time, practices and mistakes
 
3. Pack everything you do inside WSP solution and treat this as the only way of deployment into staging/production enviroment. SP is an enviroment for hosting your applications, called feature/solutions. As this is so, it is crital that all your solution should be integrated by proper deployment process. Always pack your applications in wsp packages. Your apps should be delivered inside packages, which can be passed to admin who should install it on the prod server without contacting you how to do this.
 
4. Think not only about deployment, but also about retraction. When creating applications for SP you need to consider how the solution should bahave in case of remove. What should it clear and what she left behind (in case when some components of you solution are shared among other solutions).
 
5. The big difference betwean asp.net and sharepoint development is that in case of asp.net you start by creating framework to host your application. In case of SharePoint this is done for you, but insted of that you need to know how to play with the platform SharePoint is. Is it more difficult ? no, I would say it is diffrent and you just understand that not only application will fit SharePoint and if you tried to do it this whey then you can end-up with a lot of sleep-less nights.
 
6. You can use Visual Studio to do developemnt, but you need to know that visual studio can do stuff for SP, but it is not aware of it. This causes that deplyment can be a painfull if not planed properly.
 
7. Keep away from SharePoint database. It will not give you any lights how to play with SharePoint, but it can let you brake your entire farm :). When working with SharePoint you need to underastnad that the only way of working with it is thru API.
 
8. Be really carefull with SharePoint designer. It should be used for prototyping only. You can use it to bring wire picture of your application, but on the end you should go thru normal Visual Studio path and pack your entire solution into wsp package. In general SharePoint designer should be locked for production enviroment. Use SP designer on special sandboxes , where you are not scare of losing your data (any good tool can be used for bad things).
 
9. Everything about the SharePoint is hold in database. This database contain content and metadata. This bring huge implication where you need to understand that upgrading of this structute is quite complicated process (you can not update matedata without providing the way of updating content).
 
Those are the things I believe you need to consider and keep in mind during SharePoint development. You can also listen about them in mentioned panel discussion.

Written by Mariusz Gorzoch

15 June 2009 at 22:17

Posted in SharePoint

Get me the list of installed HotFixes

leave a comment »

My today post will be connected to the previous one and it is about how to enumerate all installed HotFixes in the system. Few days ago I came across strange problem with SharePoint and as a result of my search I found that it can be resolved only thru instllation of one special HotFix. Sound quite easy?!?!… yes you can say it is, but how to findout if particular KB is not already installed in the system. And here we get to the point! How to do it ? Lucky if you are using PowerShell this is really ease task with use of WMI object called "Win32_QuickFixEngineering". The main point is to create query to this object and get the list of installed HotFixes:
 
$hf = get-wmiobject -class "Win32_QuickFixEngineering" -namespace "root\CIMV2"
 
now variable $hf contain array of all installed hot fixes. Each entry in this array contain structure like this:
 
Caption             :
CSName              : WHMPPLGDN0057
Description         :
FixComments         :
HotFixID            : File 1
InstallDate         :
InstalledBy         :
InstalledOn         :
Name                :
ServicePackInEffect : KB896358
 
and to check if particular KB/HotFix is installed we just need to filter array items by field "HotFixID". With use of PowerShell this can be done by:
 
$hf | where-object { $_.HotFixID -eq "KB896423" }
 
if you get some result, then particular HotFix/KB is installed on your computer (in my case I’m checking if KB896423 is installed) and if not, it means it is not installed.

Written by Mariusz Gorzoch

11 June 2009 at 22:18

Posted in Tip&Trick

I need this hotfix

leave a comment »

From time to time each of us need to obtain some critical patch/hotfix for the system we are mainting or using. Usually if such a patch is not avialiable for public we need to find a link/page where we can ask for it. Then we fill the form and get an-emil from where we can get the file.
What about if we could speed up this process a little bit ? What about a custom search provider for our Internet Explorer ? Hire you can find few simple step to do so:
1. Go to IE and find a search box on the top-right site
2. Click the down arrow to the right of the search button and choise "Find more providers". This should open new page for you where you can choose from existing providers or
3. choose the option to create "new search provider"
5. in the name field put "HotFix search"
6. click Install (this will create new entry on the search box drop down list called "HotFix search"
 
and you are done, now you can spend more time waching your favorite TV show:
 
 
have fun

Written by Mariusz Gorzoch

10 June 2009 at 13:30

Posted in Tip&Trick

Where the hell is ConfigDB name stored for Sharepoint ?

leave a comment »

Did you even hit the wall looking for the name of Sharepoint configDB ? Today I struggle for a bit of time trying to find it. On the beggining I was trying to simply find the command for stsadm, but soon I found there there is no "opeartion" to get name of configDB :(. You can delete configDB, you can set new one, but no option to get name of the current one :(. On the end I found somewhere on one blog that you can get this only thru:
 
– SharePoint API call (if you want to get this info quick this is not an option – at least if you don’t know powershell)
– Registry dig
 
if case of secound option, just have look at entry : HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Secure\ConfigDB and you will find your answer.
 
have fun

Written by Mariusz Gorzoch

8 June 2009 at 10:13

Posted in SharePoint