SharePoint Saturday Boston Wrap Up

So, SharePoint Saturday Boston was this previous weekend and Geoff Varosky (@gvaro) and crew did a tremendous job. Great turn out, great sponsors, great sessions, and great attendees.  Thanks to everyone who made it to my session on “Wrapping your head around the SharePoint Beast”. This continues to be one of my favorite sessions to do because the discussions it can start are always a lot of fun and it’s a great introduction for developers who have no clue what they are getting into. 

You can download my slides here:  Wrapping Your Head Around the SharePoint Beast

Also, while you are at it, consider coming to, sponsoring, or speaking at the upcoming SharePoint Saturday Ozarks on June 12th.  It’s going to be a lot of fun.

Rebuilding a .WSP File in 4 Easy Steps

If you know me by now, you know that I’m a lazy man. I’ll spend 3 hours trying to find a better way to do work that would only take me 1/2 an hour if I just sat down and did it. Hmmm… maybe I’m not lazy, maybe I’m just determined.  Yeah… that probably sounds better on a resume… so.. if you know me by now, you know I’m a determined man… if I think there should be a better way to do something, I’ll find it.  See… that sounds so much better than lazy…

So, here was my current problem. I downloaded a WSP file (SharePoint Solution File for you lay persons). It’s not important what the WSP did… It did something I needed it to do.. okay? Anyway, I deployed the WSP… the skies opened up… sun shined… sun shown… sun rays fell from the sky… angels sang… life was good…

Or was it? Ugh.. I did not like that one view… it only showed 5 items in a list at a time (and I had 20,000 items to view). However, this wasn’t just a view on a list so I couldn’t edit the page, or modify the view.  Again, don’t worry about why I couldn’t do that. I just couldn’t… okay?  The angels shut up.. clouds covered the sky.. blah.. blah.. blah…

So, this stinkin view that I couldn’t edit in SharePoint or SPD only showed 5 rows at a time and I need to browse through 20,000 entries? That’s a show stopper right there….  or was it?

So.. brilliant idea… lets crack open the WSP file, modify the view (it was just an ASPX page) and redeploy the Solution? Sounds rockin right? Okay… not so fast. If you have ever tried to extract a file from a WSP you’ve found it’s super easy.  However, if you’ve ever tried to add the file back to the WSP (or CAB) you soon realize it’s not possible.

Worse yet, if you just rename a WSP file to CAB so that you can explore it in Windows I don’t think there is a way to extract out the directory structure. So, I’m left with a mess. If I want modify a file in a WSP file I have to follow these steps:

  1. Rename WSP file to CAB and extract all the files
  2. Modify the necessary files
  3. Rebuild the correct directory structure for the solution
  4. Copy the files into that directory structure (in the right place)
  5. Create a DDF file indicating name and location of all files to be in WSP file
  6. Run MakeCab using created DDF file to create cab, then rename cab to WSP

Sound about right? None of that is too difficult, it just sounds like a lot of garbage to go through when all I want to do is modify ONE stinking little file and re-deploy.  So, I posted the question on Twitter and started quite the discussion.  From all the responses I was actually able to put together a very quick method for extracting and rebuilding WSP files. (Thanks to @ChrisO_Brien, @davidfrette, @coreyroth, @tigertoy, @rhabridge, @RemyMaza, @BrianTJackett, @sympmarc, and @SharePoint Ninja for the discussion and Help). So, would you like to know the solution??? Hear it goes…

1. Extract WSP using 7 Zip

7 Zip is a free tool that will allow you to extract your WSP files AND the directory structure it was built with. There are probably other zip tools that will do this as well, I was just not able to do it with Windows. Regardless, use a tool that let’s you extract the files and directory structure from the WSP file. 

2. Modify your files

Okay, now go in and modify the files you need to modify. Make whatever changes you need to make. Be VERY careful if messing with the XML files though…all kinds of nastiness there if you screw something up.

3. Download and use DDFGenerator from CodePlex

So, my new friend on Twitter @tigertoy pointed me to a project on CodePlex called DDFGenerator.  It’s simply an executable. All you have to do is download this executable, execute it from the command line and give it the Path to the directory structure created by 7 Zip (or whatever program you used). This will generate your DDF file for you.

One quick note, the DDF Generator does not put an entry in the DDF to set the WSP file name. So, make your life easier, open up the .DDF file and add the following line along with the ther .Set lines:

.Set CabinetNameTemplate=SolutionName.WSP

This will make sure your WSP file is named properly with the correct extension. If you don’t do this it will create a cab file called “1.cab” when you run MakeCab.exe in the next step and you will have to rename it to your solution name. Not a big deal, just something to keep in mind.

4. Run MakeCab to create .CAB File

Now all you have to do is run MakeCab to generate your WSP file using the DDF you generated. This also will be run from the command line and will look something like:

MakeCab.exe /F <ddfFilename.ddf>

After you run the above command, you will have your WSP file which you can go deploy… watch the skies open again… yadda.. yadda.. yadda…

Thanks again for all those who helped with this today. Even though it is a four step process, it is a very QUICK four step process. By far the easiest solution I have found so far. That does NOT mean there is not a better one.. if you have one, I’d love to hear it.

Thanks again!

Another Inro to CAML Blog

Yes.. there’s lots of CAML blogs out there… lots of tutorials… lots of references… So, why add to the noise??  Well… two good reasons:

  1. I need to blog about something
  2. My session at SPTechCon was on SharePoint Web Services which rely heavily on CAML in SharePoint 2007 (less so in 2010 thanks to LINQ to SharePoint, but that’s another blog).

So, it’s really important that you understand CAML or at least have a reference you can go to quickly.. so Pay Attention!!!

What Exactly Is CAML?

If you go to the MSDN site: “Collaborative Application Markup Language (CAML) is an XML-based language that is used in Windows SharePoint Services to define the fields and views used sites and lists. CAML is also used to define tables in the Windows SharePoint Services database during site provisioning.”

So, CAML is a special XML based query language used to well… query data from SharePoint.

I describe it as a combination of XML, SQL, and WTF… At first glance it appears to be overly complicated and cumbersome.  After spending time with it however you can get a sense for why it is structured the way it is..and don’t tell anyone I said this… but it actually makes sense!

So… CAML is just a Query language… If you are using the SP Object Model you can use the SPQuery Class. If you are using SharePoint Web Services outside of SharePoint you will just create a string to pass to your Web Service call. Regardless… CAML is your friend… love it… like a woman that you can’t understand and frustrates you… just accept her and love her… because like SharePoint, CAML is a woman. :)

Is It That Cumbersome? Let Me See Some Examples??

Wow, kind of pushy aren’t you? Okay… so here are some CAML examples…

For the most part you can take a “Where” clause from SQL and convert it to CAML:

Operation SQL Example Converted to CAML
Equals

WHERE City = “Harrison"

<Where>
    <Eq>
      <FieldRef Name="City" />
      <Value Type="Text">Harrison</Value>
    </Eq>
</Where>

Not Equals

WHERE City <> "Harrison"

<Where>
    <Neq>
      <FieldRef Name="City" />
      <Value Type="Text">Harrison</Value>
    </Neq>
</Where>

Not Null

WHERE City <> null

<Where>
    <IsNotNull>
      <FieldRef Name=“City" />
    </IsNotNull>
</Where>

And

WHERE City = “Harrison” and State = “AR”

<Where>
    <And>
      <Eq>
        <FieldRef Name="City" />
        <Value Type="Text">Harrison</Value>
      </Eq>
      <Eq>
        <FieldRef Name="State" />
        <Value Type="Text">AR</Value>
      </Eq>
    </And>
</Where>

Or

WHERE City = “Harrison” or City = “Harrisburg”

<Where>
    <Or>
      <Eq>
        <FieldRef Name="City" />
        <Value Type="Text">Harrison</Value>
      </Eq>
      <Eq>
        <FieldRef Name="City" />
        <Value Type="Text">Harrisburg</Value>
      </Eq>
    </Or>
</Where>

Like

WHERE City LIKE “Harris”

<Where>
    <Contains>
       <FieldRef Name="City" />
        <Value Type="Text">Harris</Value>
     </Contains>
</Where>

(OR)And

WHERE (City="Harrison" OR City="Harrisburg") AND State<>"PA"

<Where>
    <And>
      <Or>
        <Eq>
          <FieldRef Name="City" />
          <Value Type="Text">Harrison</Value>
        </Eq>
        <Eq>
          <FieldRef Name="City" />
          <Value Type="Text">Harrisburg</Value>
        </Eq>
      </Or>
      <Neq>
        <FieldRef Name="State" />
        <Value Type="Text">PA</Value>
      </Neq>
    </And>
</Where>

Order By

WHERE City="Harrison" or City="Harrisburg" ORDERBY City

<Where>
    <Or>
      <Eq>
        <FieldRef Name="City" />
        <Value Type="Text">Harrison</Value>
      </Eq>
      <Eq>
        <FieldRef Name="City" />
        <Value Type="Text">Harrisburg</Value>
      </Eq>
    </Or>
</Where>
<OrderBy>
    <FieldRef Name="City" />
</OrderBy>

You get the idea. It’s not really THAT complicated, but if you are not comfortable with XML you will be MISERABLE!

Are There Any Other Operators?

I’m SO glad you asked… why… yes.. there are more operators! I obtained the following list from an article on A2Z.net called “CAML Query syntax and options in SharePoint”.  This is actually a really great article and you should probably go read it after you are done here. 

CAML Operator

Meaning

Eq

=

Gt

>

Lt

<

Geq

>=

Leq

<=

Neq

<>

Contains

Like

IsNull

Null

IsNotNull

NotNull

BeginsWith

Text begins with

OrderBy

Sort order for a query.

GroupBy

Contains a Group By section for grouping the data returned through a query in a list view

 

There Has Got To Be A Better Way To Generate The CAML For Me!

Wow… whine much? Yes, there are several tools out there that will generate CAML for you. Some you have to install on SharePoint and can actually work directly with a specific list. I’ve always been more of a do it yourselfer/notepad-works-for-everything type of guy. I found a great simple web site that will actually generate your CAML for you.  So, you can type in “Where City=’Harrison’” and it will automatically generate the CAML for you. Pretty cool?

Here’s the link with a couple of screen shots so you can see what I’m talking about:

1. Type in your “where” clause and click the “Sql to CAML” button

    image
    2. Copy and paste the resulting CAML where ever you need it!
image

Definitely a handy tool. I’ve used it many times. The only flaw is that if there is an error in your Sql it will not tell you what the error was.

Well.. that’s it for my Intro To CAML… Hope you learned something… Thanks again for stopping and thanks to all those who came to my session at SPTechCon!

«March»
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910