Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

Thanks.

UPDATE

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()
{
    ParseUrlForVariables();
    OpenDefaultEditor();
}

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;
                    break;

                case "SaveLocation":
                    SaveLocation = variableValue;
                    break;

                case "ProgID":
                    ProgID = variableValue;
                    break;

                default:
                    break;
            }
        }
    }
}

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

</script>

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

share|improve this 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 '11 at 3:11
add comment

1 Answer

up vote 2 down vote accepted

You will need to display a page with this link:

http://hostname/_layouts/upload.aspx?List={ListId}&RootFolder={RootFolder}&ContentTypeId={ContentTypeId}&Source={Source}

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

UPDATE

Is this sort of what you want:

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

http://www.novolocus.com/2009/03/04/add-a-create-new-document-link-to-a-page

http://glorix.blogspot.com/2006/11/launching-office-applications-from.html

which gets into:

core.js

  • createNewDocumentWithProgIDEx
  • createNewDocumentWithProgID
  • createNewDocumentWithProgIDCore

init.js

  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
    }
share|improve this answer
    
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 '11 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 '11 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 '11 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 '11 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 '11 at 8:59
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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