Search code examples
sharepointfileuploadweb-parts

Sharepoint webpart upload file whitout using "runat server"


For uploading a file in sharepoint I use a webpart and an automatically generated form.

the tag for the upload file:

<input type="file" id="uploadfile" name="uploadfile" />

When I try to pick it up after posting, the file isn't accessible with the Request.Files attribute (Request.Files["uploadfile"]). (Request.Files looks like null on sharepoint)

Is there a solution in sharepoint without using the "runat=server" on the input tag?


Solution

  • To upload files to sharepoint you need to set enctype (enctype="multipart/form-data") on the form tag. Sharepoint doesn't add it when you use .

    When using non ASP.NET controls, you can use 'this.Page.Form.Enctype = "multipart/form-data";' On Page_Load to add the enctype.