Create Your Own Context Menu

You remember we talked once about getting documents to open into work in such a way that when you save it, it saves straight back the to document library.

We had this post where I reviewed the html that opens documents from the context menu in a document library.

Well, our new best friend Pedro give us this gem:

http://pserrano.blogscavedigital.com/PermaLink,guid,82933a22-3179-48a0-bfef-15b8a6744b25.aspx

Where he shows us how to completely steal the context menu code.

My current objecttive revolves around this solution:  I want a site owner to be able to edit a "Current Status" page in MSWord and then use that document as a source for a content editor web part.

And this works great; you should try this.  Assume you have a new blank site.

First create a document library using the default MSWord document as a template.  Create a document and call it SiteUpdate.htm.  Be sure to use the .htm extension when you save it.

Next, create a web part page.  Call it Update.aspx and put a content editor web part on it.  Put the URL to your SiteUpdate.htm in the Content Link field.

Then, in a second content editor web part use Pedro's code like this:

 <SCRIPT>
myCtx = new ContextInfo();
myCtx.listBaseType = 1;
myCtx.listTemplate = 101;
myCtx.listName = "{<put list GUID here>}";
myCtx.listUrlDir = "Document Library";
myCtx.HttpPath = "http://MyPortal/Resources/_vti_bin/owssvr.dll?CS=109";
myCtx.HttpRoot = "http://MyPortal/Resources";
myCtx.imagesPath = "/_layouts/images/";
myCtx.PortalUrl = "/";
if (myCtx.PortalUrl == "") myCtx.PortalUrl = null;
myCtx.displayFormUrl = "http://MyPortal/sites/MySIte/MyDocLibrary/Forms/DispForm.aspx";
myCtx.editFormUrl = "http://MyPortal/sites/MySite/MyDocLibrary/Forms/EditForm.aspx";
myCtx.isWebEditorPreview = 0;
myCtx.ctxId = 1;
myCtx1 = myCtx;
</SCRIPT>

<!– my item: BEGIN –>
<table
height="100%"
cellspacing=0
class="ms-unselectedtitle"
onmouseover="OnItem(this)"
CTXName="myCtx1"
ItemId="1"
ServerUrl="/sites/MySite/MyDocLibrary/SiteUpdate.htm"
FileDirRef="sites/MySite/MyDocLibrary"
HTMLType="Word.Document"
FileType="htm"
DocIcon="icxddoc.gif|Microsoft Office Word|SharePoint.OpenDocuments"
FSObjType="0"
COUId=""
SourceUrl="">
<tr>
<td width="100%" Class="ms-vb">
<A onfocus="OnLink(this)" HREF="http://MyPortal/sites/MySite/MyDocLibrary/SiteUpdate.htm" onclick="DispDocItemEx(this,'FALSE','FALSE','FALSE','')">
Manage Update Content
</A>
</td>
<td><img src="/_layouts/images/blank.gif" width=13 style="visibility: hidden" alt="">
</td>
</tr>
</table>
<!– my item: END –>

What you end up with is content on your page that can be edited in MS Word using the options provided by the context menu.

Mine is a little different from Pedro's; he was trying to run an InfoPath form.  Now, you can give the site owner edit access to the document libary and he or she can modify the update content in Word, click save and the content will be written right out to the web part page via the first content editor.

Groovy, no?

-robot


Tags:

 
 
 

Comments are closed.