Question

Can I make upload file form in some sandboxed WebPart for Sharepoint Online, and if I can, how can I?

I've searched a lot and found only solutions, available for Client Object Model for outside clients, there is no example how to do this with JSOM (Client Object Model for Javascript) and usual way to upload with asp:FileUpload don't work in sandbox solution, PostedFile length = 0

Was it helpful?

Solution 2

After some search I finally found solution, based on Codeplex's SPServices. There is plugin SPWidgets(https://github.com/purtuga/SPWidgets/). This plugin loads an iframe with upload.asmx (Sharepoint's default upload form), then set display: none for all elements on this page, exept input[type=file] and adds button, wich can submit form in iframe. After submit plugin catches iframe state (_onIFramePageChange event) and do some callbacks depends on iframe url.

This looks like some ugly workaround, but it is only working solution that I found after hours of search.

OTHER TIPS

You do have the option of using the ActiveX STSUpld.UploadCtl control - this enables you to provide the Multi-file upload as you see in a document library.

Note that in the following - Confirmation-URL must be set (where to go when upload is done) and the destination must be set as well to an existing document library.

<script type="text/jscript">
function DocumentUpload() {
    var uploadCtl = document.getElementById("idUploadCtl");
    uploadCtl.MultipleUpload();
}
</script>

<input type='hidden' name='Confirmation-URL' id='Confirmation-URL' value='' />
<input type='hidden' name='PostURL' id='PostURL' value='' />
<input type="hidden" name="Cmd" value="Save" />
<input type="hidden" name="putopts" value="true" /> <!-- Overwrite files -->
<input type="hidden" name="VTI-GROUP" value="0" />
<input type="hidden" name="destination" id="destination" value="/TestDL" /> <!-- Files destination path, must already exist -->
<p style="margin-left:auto;margin-right:auto;margin-top:0px;margin-bottom:0px;text-align:center;padding:0px !important; vertical-align:top;width:100%;">
    <script type="text/javascript">
        try {
            if (new ActiveXObject("STSUpld.UploadCtl"))
                document.write("<OBJECT id=\"idUploadCtl\" name=\"idUploadCtl\" CLASSID=\"CLSID:07B06095-5687-4d13-9E32-12B4259C9813\" WIDTH=\"600px\" HEIGHT=\"250px\" ></OBJECT>");
        }
        catch (error) {
        }
    </script>
<asp:Button runat="server" accesskey="O" id="OKButton" CssClass="ms-ButtonHeightWidth" OnPropertyChange="if (this.value != 'Upload files') this.click();" Text="Upload files" UseSubmitBehavior="False" OnClientClick="DocumentUpload(); return false;" />
<asp:Button runat="server" accesskey="C" id="CancelButton" CssClass="ms-ButtonHeightWidth" Text="Cancel" UseSubmitBehavior="False" OnClientClick="window.location ='<somewhere to go>'; return false;" />

Hope this helps....

There's not too many options, however check out SPServices on CodePlex - this would be the best place to start. Remember - SharePoint expects a binary object when calling the service. You have to capture the file and convert it to binary first, then call the web service to upload.

I have an example but not with me at current location - if the above doesn't get you started, let me know and I will find and post.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top