0

I need to upload image file into the sharepoint 2010 picture library using java script...

requirement is --

1.we have File Upload control

2.And, we have to upload image file from that file upload control

Please see code...But this code is not working (showing "Undefined object" exception for 'File' or 'FileInfo')

If any body have better solution that would be nice.

Thanks in advance.

<script>
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Test');
//var fStream = (new FileInfo(uploadimagepath)).OpenRead();
var fStream = File.OpenRead(uploadimagepath);
//var fStream = FileUpload.PostedFile.InputStream;
//var contents = new byte[fStream.Length];
var newPic = oList.RootFolder.Files.Add(phototitle, fStream);
var oItem = newPic.Item;
oItem.set_item('Title', phototitle);
oItem.update();
oList.Rootfolder.Update();
clientContext.load(oItem);
</script>

1 Answers1

0

you cannot use the uploadimagepath, it gives you the path from the client.

instead use the file stream which is sent from client to server.

check this url for understanding the file upload control better

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx

  • Link which you mentioned is about C# but i have to use java script (ECMAScript) in SharePoint 2010. I have used file upload control as well in my code (see commented lines...) but same exception got for file upload control. – Lalit Kumar Mishra Sep 27 '12 at 07:49