Click here to Skip to main content
15,883,705 members
Articles / Web Development / HTML
Article

Creating and Deleting Files on Fly on WebServer through Javascript (Magic of HTML and Jquery)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL2 min read 8.3K   1  
Creating and Deleting Files on Fly on WebServer through Javascript (Magic of HTML and Jquery)We usually know the methods of POST and GET for posting

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Creating and Deleting Files on Fly on WebServer through Javascript (Magic of HTML and Jquery)

We usually know the methods of POST and GET for posting and fetching data from WebServer.

There are many other HTML verbs used . Two of them are PUT and DELETE

PUT - used for moving,updating creating files through WEBDAV on webserver.

DELETE - used for deleting file through WEBDAV on webserver

WEBDAV - Web distributed Versioning and Authoring originally developer by IEE and accepted by HTML community as a standard for various Webserver functioning.

 

As though it is not easy to create a request for PUT and DELETE as it contains raw html and do not use forms.

but through JQUERY we can acheive this in a much simple way.

 

1) jquery has ajax function which helps in creating ajax requests asynchronously

2) we can setup this call this ajax function for creating a file on webserver.

$.ajax( {data:'MyTestData', type:'PUT', url:'http://localhost/TestWeb/TestFile.txt' } )

Here we are setting up ajax request for PUT verb which will create a file TestFile.txt on TestWeb Folder with data

'MyTestData' written into it.

If we want to insert some heavy data into this file we can also use like this

$.get('http://localhost/TestWeb/Default.aspx' , null, function(testdata) {

 $.ajax( {data:testdata, type:'PUT', url:'http://localhost/TestWeb/TestFile.txt' } )

}, null);

 Here we have requested data for page Default.aspx which will return HTML code for page through ajax.

function(testdata) is function which get called when ajax request has been successfully completed with the testdata as return value from response.

We can then pass this testData to our previous method which will create file testFile.txt on server and insert the data into this file.

 Same way we can also do for DELETE

 $.ajax( { type:'DELETE', url:'http://localhost/TestWeb/TestFile.txt' } )

Here we dont use data option as we only want to delete the file from server.

 

So in a way we can create files and delete them on fly just by using simple jquery and knowledge of HTML verbs.

 

.

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --