purtuga / SPWidgets

Sharepoint Custom UI Widgets
74 stars 34 forks source link

SPControlUpload - SP2010 custom application pages #33

Closed varismii closed 9 years ago

varismii commented 9 years ago

Hi,

I managed to get this component work nicely in standard HTML5 page.

But when I migrated the page to a custom SharePoint Application Page, then it stopped working.

No errors in JS console. Shows immediately a dialog with the following text: "Error encountered during upload which is causing program to loop. Last upload error was: File Not Found."

I managed to track the issue to the following JS libraries: _layouts/1033/init.js /_layouts/MicrosoftAjax.js

Removing those rows from the page source makes the Upload component to work again. Not sure why?

Any tricks or hints how to get rid of the error and make it work again?

I'm using the minimal SP2010 application page template: http://allthatjs.com/tag/sharepoint-2010-csom/ spwidgets upload ok spwidgets upload error

purtuga commented 9 years ago

Hi @varismii The error being thrown is actuallly coming from this widget - Line 964 of source. What's happening is that it seems to be looping between the "working on it" SP page and the upload page... I'm thinking there is something custom on the Upload.aspx page that this widget is not coded to recognize.

I think this is being thrown after you pick the file and the upload start up... but can you clarify the steps you took after the widget is shown on the page...

  1. Where you able to select a file from your computer?
  2. Where you able to click the 'upload' button after that? and is it at that time thtat you get the Looping error?

A few ideas

1

Try to upload the file using the SP UI... just copy the url from the console (the one displayed as Upload.aspx?List=... (copy full url) - let's see if that works... This is just to ensure that the flow that this widget follows in the "background" is actually working...

2

Another thing: I noticed that both Upload.aspx and UploadEx.aspx are attempted to be used... this could be the problem (which I thought I had code to handle it - here )... Change your input to SPUpload to include the 'uploadPage' options and set it to your_site_root_web_url + "/_layouts/UploadEx.aspx".

If this one address the issue, then I would love to see what $.SPWidgets.getSPversion() is returning.

3

You said it works with HTML5 standards mode... Maybe this is an option - https://paultavares.wordpress.com/2015/01/20/how-to-render-a-sharepoint-page-in-ie-using-edge-mode-without-changing-the-master-page/ I assume this is happening only with IE, correct? Does it work on Firefox/Chrome?

varismii commented 9 years ago

Hi,

Workflow:

I tested your ideas:

1

I tried the URL from Network Console: http://www-author.devbox.dev/_layouts/UploadEx.aspx?List={EA3BD20D-85E4-456A-8E5A-03A90D79EF1D}&RootFolder=http%3A%2F%2Fwww-author.devbox.dev%2FCaseStudies&Source=%2Fundefined&1423496851409=1&

It gives a SharePoint error page with: "File Not Found.".

In my case error situation it only tries UploadEx.aspx, not Upload.aspx. When I modified the above URL to use Upload.aspx, it opens the SharePoint single file upload form just great. Good catch! I missed that totally.

So I just need to figure out now how to get the component to use Upload.aspx instead of UploadEx.aspx.

2

Hmm, I read your answer and link. I suppose the SP version identification is not working. Our platform is SP2010. I did a quick JS debugging. It seems the code gets '14' from SP.ClientSchemaVersions (see the attached image). Which is good since _spPageContextInfo does not return anything as I cannot find the required DOM element from the minimal SP application page.

So the solution is simply just what you suggested. Adding the 'uploadPage' parameter: siteRoot + '/_layouts/Upload.aspx',

That makes it work.

spwidgets upload version debugging

3

I'm using Firefox for all testing. Although the ready solution needs to work in IE also (corporate stuff, you know).

So now It works fine in Firefox. I tested in IE10 to make sure => kaboom! JS security exception => permission denied accessing iframe content (see the attached screenshot). Funny thing is that it still managed to upload the file to the SP DocLib! I tried the manual IE browser engine change and the IE=8 meta tag workaround - to no avail. I'm guessing this is a browser security settings issue in my development environment (hopefully) - either the IE on Windows Server 2008 R2, or the AD security policies are set too tight. Or the dynamic IFrame DOM manipulation this component is based on is just too much for the latest IE browsers. Who knows...

spwidgets upload ie ex

Single click upload?

This is an off-topic quick question: Is it possible to trigger the SPControlUpload component to upload a known file (say, from http://server/file.txt or c:\temp\file.txt) without the file browse dialog (use just the button)?

It's in my project requirements that uploading should preferably be via a single button click (we always upload the same updated file).

Thanks for great support and answers!

purtuga commented 9 years ago

Interesting that using the UploadEx.aspx page does not work.. In my prior testing it did work... Actually, If I remember correctly, SP was automatically redirecting to the UploadEx.aspx page when I tried to use the old Upload.aspx page instead...

So Idea 2 works - that's good... I had this option in there for cases where a customized upload page might be in use... Again just make sure SP is not redirecting from Upload to UploadEx.

Idea 3 might be failing because of the way I'm trying to find the iframe... and now that I think about it a little more, I probably should not have suggested it.

Re: Single click upload

Its not supported in its current implementation, but if the browser supports HTML5, you might be able to set the value of the upload input via the File API...but remember that unless you changed something in the master Page, SP2010 tells IE to render the page using IE8 rendering engine - I don't remember now the level of support for the File API in that version of IE. To do this, you would have to reach into the iFrame and find the file input... probably using the onPageChange input parameter...

varismii commented 9 years ago

Yes, the 'uploadPage' parameter came to the resque. Good thing you had added it to the component. In our current project the Upload pages are not customized, but I've come across SP projects where they have been (copies of original with different names, users redirected there with some HTTPHandler or jQuery DOM link manipulation).

Thanks for the tip to use 'onPageChange' parameter to further customize (automate) SPControlUpload behaviour. I'm hoping the customer is willing to bear the upload in 2 steps circulating the file on computer before each upload. I quickly checked the possibilities of File API, and it sounds promising, but it requires IE10 for full support and our customer has IE9 as corporate browser: http://caniuse.com/#feat=fileapi. Pity.

Thanks again for help.

purtuga commented 9 years ago

Yeah, IE9 def. will not do it... Good luck with the project...


Paul T