Thursday, January 29, 2009

Embedding Video for a Sharepoint List Item into Dispform.aspx




So, you want some details? First, here's what we're looking to create. It's a modified version of dispform.aspx. The list item actually has about a dozen fields, but the only ones I'm interested in displaying are the four you see at the top, as well as displaying the related video.

To start, I created a new form and applied the dispform formatting to it--don't just modify the existing dispform.aspx, or you're asking for trouble. There's plenty of resources telling you how to do this; just google sharepoint designer new dispform.

If you're familiar with the way dispform.aspx works, you might notice something strange about my page design. If you're not, here's the simple version; the fields at the top of the window and the "Created" and "Last Modified" fields at the bottom (as well as both "Close" buttons" are actually all part of one data view. I wanted to throw my custom content right in the middle, but I don't know how to (or even if you can) break that view up.

So, I did the next best thing. First, I put in a single row, two column table at the very bottom of the page. This was easiest to do in Code view, by just typing the table code in between the "" tag and the tag. For my purposes, I made the table width 100%, and the width of the first column 60% (but your formatting may demand something else--or maybe even more or fewer columns; you'll see why below). Then, I copied the entire WebPartPages:DataFormWebPart tag (basically 99% of the file) to the clipboard, and pasted it *after* my new table, but before the final tag. So, I just duplicated my Data View of the list item.

Now, if you switch back to Design view, you'll see the list item duplicated (along with Close buttons, created and modified information, etc) with a small table in between. But we're not done with the duplication yet. If you save the file and attempt to browse to it on your Sharepoint site, it'll blow up. Each item on a page requires a unique GUID, and while Sharepoint Designer will render the content, Sharepoint cannot.

So, we need a new GUID. Again, there's plenty of online tools to generate them for you. Find the "id" parameter in your second (pasted) WebPartPages:DataFormWebPart tag (the value starts with "g_"), and put your new GUID in that field. Note how it needs to be formatted, with a leading g_ and the dashes replaced by underscores. Then about two lines below that for "SharePoint:SPDataSource" and change it's id (this one isn't a guid; it's just text) by adding a "1" and the end of it.

Now we need to get rid of some of the duplicate data. Since I didn't want to display any of the field values in the bottom "copy", I just selected the table that all of the values were in and deleted it. You may want to just hide it instead, which is what I did with everything else I didn't want to show up.

To hide something on the page (make it so Sharepoint doesn't render it in the browser), you either set it to Visible=False (for those tags that support it), or you change it's style. Most everything here is in a table, so the style method is easiest. To hide a certain field from displaying, select the row it's in (don't forget about the tag chain above your page in Sharepoint Designer--just select your field and use the chain to work your way up to selecting the row), and change it's style property to "display=none". Just do this for everything you don't want to display (or display twice).

At this point, we haven't even touched video, but we're ready. My page required the video and "related links" be inserted. The related links (named "External Resources" on the example above) is a simple data view web part. In fact, the video is a data view web part as well. I brought up the Web Parts task pane and inserted new web part zones into each of the cells of the table I created at the beginning of this post. I created my data view web part for the links following the instructions in the link I posted yesterday. I just stopped after creating the filter, because I wanted this one to be a data table.

I created another data view web part in the other web part zone, again, following the same instructions. But this time I needed the XSL for changing it from an HTML table to an embedded video player. Getting the XSL to work was difficult, to say the least, and since this is getting SOOO long, I'm going to explain why in my next post. Instead of explaining the XSL here, I'm just going to give it to you straight up. The only thing that should be in any way custom to this is the field I store the Video URL in; the video URL is stored in a column called (ironically) "Video URL". This URL can be any valid URL that points to a Windows Media file. Changing it to support Youtube would be pretty straight forward, and I'll talk more on that later. But for now, here's the XSL file--just copy it and paste it into a new file in your Sharepoint site, and follow Greg Chan's instructions on pointing your data view to it. With this you don't need to worry about anything that he says in regards to modifying the XSL for the data view part--basically just create the data view so that it returns the record (in a table) that you want, and then change it's XSL template in it's properties.
(I'm having trouble getting the XSL file to upload; I'll include it in the next post)




Wednesday, January 28, 2009

Why is my programming starting to look like a card from Grandma?

I've typed so many X's and O's in the past day my eyeballs are swimming. I'll post more about it later. It seems like I'm spending most of my time now pretending to understand x?l. I miss the days of

10 Print "Hello, World"
20 Goto 10

Short version is that I've finally got my weekly topics for the 2009 Organizational Push working. Since it doesn't look like my employer will really be able to make money this year, we're going to try to get everyone a little more organized. Every week I'll be publishing a new "topic", which will really just be little more than some tips and (usually) a brief video about a certain way of getting more organized. "Bite Sized Information" has been my motto the past two months.

All of this stuff will be published with Sharepoint. I've got a pretty standard List that will contain an entry for each topic; I really didn't want to create a new web part page for each item to display related links and the embedded video, though. But I've had a heck of a time figuring out how to modify dispform.aspx to include custom content. I got part way a while ago, figuring out how to modify the form (or modify a copy--I'm too smart to modify the original...well, I am now :) ) to include a web part zone. With that I can do a data view web part to display related links and other list items.

The tough part was the video--I wanted to embed it, while still having the embedded player load the video from the "Video URL" column of the particular list item. After spending about 6 hours pouring over a related Sharepoint Developer Blog Entry by Greg Chan, I figured it out. I can now embed a player and have it use the video file referenced in the list item. That means I can just format one page, rather than 48.

Next post I'll share how it works. It'll be a biggy.

Thursday, January 22, 2009

C:\Windows\Installer handles my Icons? huh...

I've been trying to slimline the installation on my laptop; I've had to rebuild it a few times in the past month (for various reasons), and I'd like to get an image small enough that I can squeeze onto my USB flash drive (now up to 4GB, thanks work!). Two folders in the Windows directory jumped out at me:

C:\Windows\SoftwareDistribution. Apparently this is where all the installs for various Windows Updates go. The "Download" folder under this is essentially temp storage that never gets cleared out, so it can be emptied. I guess if you ever plan to uninstall any updates, you need the other contents of this folder.

C:\Windows\Installer. Everything I read implied that this was a cache of installations for programs that you install via CD or another "terrestrial" method. I read that you can move it, and you should be fine.

So I moved it to my old USB Flash Drive. And all my icons disappeared.

Specifically, the icon for just about every program turned into that generic "Windows" icon. It also affected documents--documents that opened in programs with bad icons also had bad icons themselves. I tried the usual (delete the icon cache, reboot, etc.) and no change. I moved the Installer folder back from my flash drive, though, and all of the icons reappeared.

So, the moral of the story is that, if you choose to move C:\Windows\Installer, make sure you move it to a drive that actually remains connected to your computer...

Sunday, January 04, 2009

Well, that was a flop

Do you know how to tell that your ice melting experiment isn't going to work? When you go outside to set it up, and hanging from the cables that gave you the idea are a bunch of icicles.

So much for using the cable company to keep my roof clear. :)