Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
23 Jan 2011 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here