I'm currently working on integrating some SharePoint functionality to an existing C# application we have here. Most of the requirements have be fairly easy to implement: I'm using the ListData REST service to display documents in a Library; I'm using Lists.asmx to Check-out and Check-in items so I can edit their metadata; and a few other simple operations.

I'm stuck, however, on the following requirement:

The user of the external C# application must be able to trigger the creation of new Library Documents from within the C# application. If only one ContentType exists in the Library, open this new document window. If multiple ContentTypes exist, prompt the user for a ContentType and open the corresponding new document window.

I've managed to fetch the list of ContentTypes for our Library and have the user select one, but after that I'm at a loss.

I can't seem to figure out how to open the default new-document Editor for any given ContentType. (ex, a web editor for Forms; Word for docx files; Excel for xls files).

The idea is to allow the user to create the document on-the-fly as opposed to creating it beforehand and then uploading it.

Can anyone point me in the right direction?



I ended up using the following javascript code, which is put together from the answer selected below.

<script language="Javascript">

var Template = "";
var SaveLocation = "";
var ProgID = "";

ExecuteOrDelayUntilScriptLoaded(DoWorkAndClose, "sp.js");

function DoWorkAndClose()

function ParseUrlForVariables()
    var getString = window.location.search;

    if (getString && getString.length > 1)
        getString = getString.substr(1);
        var variableValuePairs = getString.split("&");

        for (var i = 0; i < variableValuePairs.length; i++)
            var splitPair = variableValuePairs[i].split("=");
            var variableName = splitPair[0]
            var variableValue;
            if (splitPair.length > 1)
                variableValue = splitPair[1];

            switch (variableName)
                case "Template":
                    Template = variableValue;

                case "SaveLocation":
                    SaveLocation = variableValue;

                case "ProgID":
                    ProgID = variableValue;


function OpenDefaultEditor()
    createNewDocumentWithProgID(Template, makeAbsUrl(SaveLocation), ProgID, false);


The problem I'm having now is finding the ProgID... but that's for another question :)

  • You should move your update into its own answer as it's not a part of the question. It would then be polite to flag a moderator to make it community wiki, since it's based on @djeeg's answer.
    – Alex Angas
    Apr 14, 2011 at 3:11

1 Answer 1


You will need to display a page with this link:


If you go into list settings -> advanced, you can turn off dialogs. Then you can see the url that the "New Document" does


Is this sort of what you want:

createNewDocumentWithProgID('http:\u002f\u002fwssdev\u002fDocument Library\u002fForms\u002ftemplate.dotx', 'http:\u002f\u002fwssdev\u002fDocument Library', 'SharePoint.OpenDocuments', false)



which gets into:


  • createNewDocumentWithProgIDEx
  • createNewDocumentWithProgID
  • createNewDocumentWithProgIDCore


  function StsOpenEnsureEx2(a) {
        ULSA13: ;
        if (v_stsOpenDoc2 == null || v_strStsOpenDoc2 != a) {
            v_stsOpenDoc2 = null;
            v_strStsOpenDoc2 = null;
            if (window.ActiveXObject) try {
                v_stsOpenDoc2 = new ActiveXObject(a);
                v_strStsOpenDoc2 = a
            } catch (c) {
            //non-ie stuff
        return v_stsOpenDoc2
  • Thanks for the reply. I'll give this a shot. Quick question: Is this a method for uploading existing files as new documents, or having the SharePoint webserver trigger the creation of a new document?
    – MetaFight
    Apr 11, 2011 at 8:45
  • this is should be how to: "open the default new-document window for any given ContentType". if you need help with uploading documents via code can you create another question
    – djeeg
    Apr 11, 2011 at 8:46
  • Hi djeeg. I just tried your answer. It's not exactly what I'm looking for, though. I'm looking for a link that will open the ContentType's default editor. I'll modify the question to make that clearer. Thanks anyway.
    – MetaFight
    Apr 11, 2011 at 8:52
  • the first action when adding a new item to a document library is to upload the document, the next step is to modify the content type metadata. have you got another way to upload the document?
    – djeeg
    Apr 11, 2011 at 8:56
  • I'm trying to achieve the analogue of visiting the Library on the SharePoint website, clicking the 'Documents' tab on the Ribbon, opening the 'New Document' drop-down, and selecting a ContentType. This doesn't ask the user to upload a document. Instead it opens the default editor allowing them to save a new document, or, if they change their minds, cancel the editor and leave the library unmodified.
    – MetaFight
    Apr 11, 2011 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.