views:

560

answers:

2

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?

A: 

Is there a reason why you can't just use the ASP.NET FileUpload control? This will do all the hard work for you.

You can access a stream for the file via the FileContent property or as an array of bytes via the FileBytes property. Its filename is available via the FileName property.

Alex Angas
I'm using a self-made lightweighted framework, and try to avoid as much as possible the ASP.NET controls. But if there's no work around, I will use the basis ASP.NET FileUpload.
John Zuijderwijk
That's an admirable goal. There may be a way, but SP inserts some pretty low-level stuff as you can see from web.config. This is probably what's causing the problem but an expert in ASP.NET and SharePoint may know for sure.
Alex Angas
+1  A: 

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.

John Zuijderwijk