I would like to upload a file into share point using FORM POST. I am trying in this way
<FORM NAME="oForm" id="oForm" ACTION="<site>/_layouts/Upload.aspx?List={A4793E2B-3081-4668-B6F1-0A013159F9B1}&RootFolder=/sites/servdeldocmgr/Test SOAP2" ENCTYPE="multipart/form-data" METHOD="POST">
<input type="file" name="file1" id="file1" />
</FORM>
In onclick of a button I am doing form post. But It's not uploading. I found .net based solutions but my case is only with javascript and html.
The best is to rely on SharePoint API, populate the item (e.g SPList) and upload the file. I will provide some sample code later as I can't recall the exact function.
EDIT:
http://msdn.microsoft.com/en-us/library/dd587349(office.11).aspx has some good code snippets to get you started.
I am able to add attachment to list item. I put my experience here. Instead of uploading to upload.aspx, I achieved differently. I am able to achieve without .net, I found many .net solutions but again it will be one more programming language in application stack so I didn't use it.
http://myveda-yvb.blogspot.com/2010/01/my-learnings-sharepoint-web-services.html
Related
#Ajax is not being recognized in razor views for my MVC application. I believe the reason is bc Unobtrusive Javascript isn't allowed for the newest version of VS Mac?
To fix this problem "the web" advises adding below to the web.config of the project.
enable unobtrusive JS screenshot
However .Net Core doesn't have that, now has appsettings.json, which looks like this:
appsettings.json screenshot
Anyone know how to allow unobtrusive-Javascript in JSON?
In Asp.Net core, When you use the input tag helpers to generate the input fields, it does generate the html 5 attributes on those inputs used by jQuery validate & unobtrusive validate plugin, based on the data annotations you have on your view model properties. As long as you include the needed 2 javascript files in your page, the client side validation will work. You do not need any web config setting or anything like that.
Just include these 2 files to your page/layout
<script src="~/js/jquery.validate.min.js"></script>
<script src="~/js/jquery.validate.unobtrusive.min.js"></script>
Assuming the 2 files exist in the js directory in the static content root (wwwroot directory by default)
Assuming you also have the span element for showing the validation errors along with your inputs.
<form asp-action="Create" asp-controller="User" method="post">
<input type="text" asp-for="Code" />
<span asp-validation-for="Code" class="text-danger"></span>
<input type="submit" />
</form>
These 2 files are dependent on jQuery. So make sure you included that script as well.
I would like to know if it is possible to upload a binary file via ajax and php, and have a link to download it. I would like to avoid refreshing the entire page, as with a standard html form. So far I have been using forms to get information, such as radio and text boxes, and using javascript to override the default behavior. Is a similar thing possible for uploading a file?
It isn't possible to submit a file through Javascript.
Your options are:
The hidden iframe trick, popularized by Google. Implementing this yourself can result in some klunky stuff so there are libraries out there, such as jQuery, which have plugins, such as jQuery's popular Form Plugin, that automate this so you don't have to feel dirty inside when using it.
Using Flash to faciliate the process. Most notably SWFUpload is very popular. All things being equal, I'd probably go with the Javascript solution over this, but I've used this in the past with success. The cool thing about this solution is that it comes with a nicer interface such as loading indicators and thumbnails and such. At this point, though, you're asking for a user to have Flash + Javascript available, which may not work in some situations.
Using Silverlight instead of Flash, although I wouldn't really consider this as a viable solution, as it has a much lower penetration rate than the other two solutions.
While you can't upload a file via AJAX, you can put a file control in a popup and then update the page that spawned the popup when it closes.
I'm not too clear on how to update the page that spawned the popup, but I've seen it done in the ANGEL Learning Management Suite.
Have an IFrame (display:none) on your form and set your form's target to be that iframe.
My form looks like this:
<iframe id="upload_target" name="upload_target" src="" style="width:0px;height:0px;border:0px solid #fff;"></iframe>
<form enctype="multipart/form-data" name="frmXMLUpload" target="upload_target" action="scripts/uploadXML.php" method="POST" onSubmit="return checkExtension(fXMLFile.value, 'xml')">
<!--only allow up to 30k of data to be uploaded-->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="fXMLFile" id="fXMLFile" type="file" accept="text/xml" size="50" />
<p><input type="submit" value="Upload" /></p>
</form>
And deal with response in yuor IFRAME. basically this is not AJAX at all, but who would like JavaScript to have access to files on your local computer? It's fine the way it is.
It is not generally possible to do this in AJAX / Javascript alone.
Take a look at:
http://www.codeplex.com/SLFileUpload/
for a way to do it inside a silverlight application.
or:
http://www.element-it.com/Examples/MultiPowUpload/SimpleUpload.html
in flash.
As John Gietzen said, you can't do this directly through AJAX (ie send the actual data through AJAX). What you could do though, ispost your form to an invisible iframe, then use AJAX to ask the server for the URL. That would retain the basic user experience - not refreshing the page.
Have you considered jquery? There are nice plugins to do this gracefully.
Like this one for example: http://www.phpletter.com/Our-Projects/AjaxFileUpload/
Take a look at this example, I the plugin a little better than the one at phpLetter, though the phpLetter might have better examples for the PHP side of things.
http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Examples
You might also want to have a look at SwfUploader , which does file uploads using Flash, showing a progress bar, and without needing for the page to be refresh. Demonstrations can be seen here.
Lets say, I have a simple HTML page with
<input id="input-file" type="file" />
this input field is NOT part of any form. User chooses a file from file system for this input.
How can I load contents of file chosen by user to a JavaScript variable (e.g. as a string or somehow compressed) when some BUTTON is pressed?
I can use only pure javascript or dojo/dojox.
If this is impossible or hard to do, the input can be part of a form. Nevertheless the goal still is to save the contents of a file to a javascript variable.
The solution should be well supported even by the browsers that are not the newest (2014).
You could use the File API which is getting support in some of the newer browsers. Read more about it on this SO-thread which deals with the same problem you are describing: https://stackoverflow.com/a/754398/844932.
EDIT:
According to this link, http://caniuse.com/#feat=filereader, the FileReader API is fairly well supported today (IE10+ and all other relevant browsers), so I think you'll probably be well off using it.
I'd like to create a search box on the home page of my site that would be able to search the entire site. I know it's a very general question but I'd be very happy with just a general conceptual answer is there anyway to do this?
You can't really do this using Javascript. You'll have to use some sort of server-side language that has access to your database. Alternately, you can use something like Google Custom Search Engine to provide searching capabilities.
Once you start wanting users to be able to search your site, it implies that your site is larger than just a few simple HTML pages. Have you thought about using something like Drupal, Joomla!, Wikimedia, or some other CMS? Most of those have search capability built in (one way or another).
People are going to tell you no. They're mostly right that his probably isn't the best way to do this.
But depending on your site, it may be technically incorrect to say this can't be done with JavaScript. If all the documents you want to be searchable have a unique URL that's used throughout the site, and if their graph is connected, I think you could write a spider in JavaScript that begins indexing all these pages as soon as a user hits your site. It'd do what any other spider did: look for links on the current page, request the documents behind them (using XMLHTTPRequest or a frame or popup window of some kind), process the document and index keywords based on some scheme, and store the results (possibly in a a cookie).
Of course, duplicating all this work for each visitor doesn't make a lot of sense, which is why the other people telling you no are mostly right. But it's theoretically possible.
This is would involve much more than just Javascript and depends on a number of different variables. Often, sites are built on a MySQL (or similar) database. If this is true in your case you may want to use some PHP to get into it and search through each record. Here's an example using PHP and MySQL.
For the form, something like this will work:
HTML
<form action="?" method="get">
<input type="text" id="search" name="search" />
<input type="submit" name="submit" id="submit" value="Search" />
</form>
Then you'll need to use some PHP, assuming you want to search the title and body of one table of blog posts:
$search_terms = mysql_real_escape_string($_GET['search']);
$resc = mysql_query("SELECT * FROM blog_posts WHERE title LIKE '%".$search_terms."%' OR body LIKE '%".$search_terms."%'");
$posts = mysql_fetch_assoc($resc);
now $posts is an array containing all of your posts which match the search terms in their title or body.
NOTE: In order to search for text type MySQL fields you will need to make the field a FULLTEXT index.
Check this link out for more info: http://devzone.zend.com/article/1304
This is a VERY SIMPLE solution, but it will get you on the right track.
Does any one know how to make a file upload control in javascript. For example, one using a texbox and a button.
Dupe of Javascript file uploads
Plain HTML:
<input type="file" />
To programmatically create one using javascript:
var el = document.createElement('input');
el.type = 'file';
document.body.appendChild(el);
If my understanding is correct based on this and your previous topic, you're trying to upload a file PURELY in javascript. If this is the case, please note that this is not possible. You're going to need something on the server side to gain the request. Now, however, if you're looking for something that uploads in an "ajax" fashion, there are workarounds to do this by sending the request through a hidden iframe. I know JQuery has this capability built in.
If you need it to open a dialog (or if you need the ability to select multiple files) you need to use something like SWFUpload.
It is impossible to complete your task using pure javascript and using no fileinput html tags, as it is the only thing that allows you to select/upload files. You can only style it.
The other way, as suggested by soprano, is to use some Flash/Java based uploader.
Although the author of the question asked about form file input styling, I want to let you know that pure JavaScript, AJAX-style uploads are possible with FireFox 3 and greater.
I wrote an exhaustive tutorial about this new feature on my blog.