views:

56

answers:

4

We use MOSS 2007, and I have a document library with several document templates in it. When someone clicks the document template (for example .dotx), the templates is opened. But I want it working so that a new document is opened based on the template.

I can do this with the New button in the toolbar above the list, but I do not like this, and it is not as easy to use for the SharePoint users.

There is a workaround, the user has to click at the right side of the name of the template, then go to the menu 'Send To' and choose 'Download a Copy', in the popup they have to choose 'Open' to create a new document based on the template.

I did found some javascript that can be used to create a new document based on a template:

<a href="javascript:createNewDocumentWithProgID('[template path],
  '[default save dir]', 'SharePoint.OpenDocuments', false)">
   Create new document
</a>

I really want to use this, but is there a way to add this script to a link in a column in the document library list?!? I tried a new column with type Hyperlink, but an URL starting with 'javascript:....' is not a valid url according to SharePoint.

Or is there another way to accomplish this, a column in an existing list with some text, and if you click on that text, a document will be created based on the template.

A: 

Maybe you should try a Multiple Lines of text column with your HTML link inside of it?

Vladi Gubler
I've tried this, but this does not work, when putting <a href=... >...</a> into a text column or multiline column, the link is not shown, but the full html-tag text is shown.
Dennis
even when you edit the HTML directly?
Vladi Gubler
How do you mean this? When I add a text column to a document library, i can (for an existing document), choose for edit properties and then fill in the text column. By my knowledge, this is the only way to do this. Or is there some other way?
Dennis
Or do you mean that I should do something like described in http://www.codeproject.com/KB/sharepoint/FckEditorSharepoint2.aspx
Dennis
No, I meant the Richtext column where you edit the HTML directly, not a custom column
Vladi Gubler
A: 

Use CDATA. Here is a piece of code from my current project :

<Field ID="{39766DD4-4C81-4b04-9A14-46F7CE64567E}"
        Type="Computed"
        Name="LinkFormHistory"
        StaticName="LinkFormHistory"
        DisplayName="Form Status"
        Filterable="FALSE"
        ReadOnly="TRUE"
        SourceID="http://schemas.microsoft.com/sharepoint/v3"&gt;
    <FieldRefs>
      <FieldRef ID="{5E44AAA6-F90D-4bce-9E90-E891DC399A5B}" Name="form_status" />
      <FieldRef Name="UniqueId" />
    </FieldRefs>
    <DisplayPattern>
      <HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML>
      <HttpVDir/>
      <HTML><![CDATA[/_layouts/CEAC/Pages/HistoryPage.aspx?]]></HTML>
      <HTML><![CDATA[RelatedListID=]]></HTML>
      <List/>
      <HTML><![CDATA[&RelatedListItemID=]]></HTML>
      <LookupColumn HTMLEncode="TRUE" Name="UniqueId"/>
      <HTML><![CDATA["]]></HTML>
      <HTML><![CDATA[ onclick="GoToLink(this);return false;">]]></HTML>
      <Column HTMLEncode="TRUE" Name="form_status"/>          
      <HTML><![CDATA[</A>]]></HTML>          
    </DisplayPattern>
  </Field>
MegaHerz
In which kind of column type should I put this code? A multiline columntype can only contain max of 255 characters...
Dennis
You should create a new computed field (Type="Compute") like in the example above, generate DisplayPattern using CDATA and add this column to View. More info about DisplayPattern is here : http://msdn.microsoft.com/en-us/library/ms435494.aspx
MegaHerz
* Type="Computed"
MegaHerz
Should I edit some xml file in c:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\XML\ in the SharePoint server to accomplish this? And if so, which file, and where should I put this code?
Dennis
Read please about adding a field to the document library. http://it.toolbox.com/blogs/sharepoint-blog/adding-a-field-to-the-document-library-template-14372
MegaHerz
+1  A: 

Look into a computed column. You can use his to generate html code

brian brinley
The only columns that I can choose are: Single Line, Multiple lines, Choice, Number, Currency, Date and Time, Lookup, Yes/No, Person or Group, Hyperlink or Picture, Calculated, Business data. I cannot find the 'computed column'.
Dennis
Computed columns are part of the view settings, a calculated column is similar if you want to store tha values in the database as part of the list attributes.
brian brinley
When I create or modify a view on the Document Library, the columns that I can choose from are: Type, Name, Modified, Modified By, Check In Comment, Checked Out To, Content Type, Copy Source, Created, Created By, Edit, File Size, ID, Name, Name, Title, URL and version. I do not see a Computed column, or do I not understand you correctly?!?
Dennis
unfortunately I don't have the time at the moment to lookup myprevious code I used but here is a great article. http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/
brian brinley
Finally i did get it to work with the solution described in the link http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html.
Dennis
A: 

Finally i did get it to work with the solution described in the link http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html and thanks to brian brinley

Added a Content Editor Web Part to the page where the document list is added. Put in the source code downloaded from: http://pathtosharepoint.com/Downloads/

-> Topic: HTML Calculated Columns -> TextToHTML-V2.1.1 - (Full version)

The CEWP should be places underneath the Document Library, then add a column to the library (a simple text column), and add the following text to that column:

<DIV><a href="javascript:createNewDocumentWithProgID('[http template path]'
, '[http: default same location]', 'SharePoint.OpenDocuments', 
false)">New document</a></DIV>

And you will get a link named New document, that opens new document based on the template.

Disadvantage 1:
I think this can be made better by using a calculated field, but I did not get the URL of the current document into a calculated field.

Disadvantage 2:
The new column is not also a property of the document. When opening a Word 2010 template this way, the 'Document Properties - Server' bar is shown and you can alter the content of the field that contains the text

Dennis