Connecting Tech Pros Worldwide Forums | Help | Site Map

Delete a file in Web Share C#

Newbie
 
Join Date: Oct 2008
Location: Coimbatore
Posts: 29
#1: Jan 2 '09
we are able a download File from the Web share using Web client


Can we do same for Deleting a file

or

Some other code sample to do this

Thanks in Advance

With regards,
Mani

Newbie
 
Join Date: Oct 2008
Location: Coimbatore
Posts: 29
#2: Jan 2 '09

re: Delete a file in Web Share C#


Hi

I've a C# windows application that scans for Zip files at a remote URL
address and downloads them to the local machine when they arrive. I
can do that OK with HttpWebRequest or WebClient.


After they've been downloaded I want to delete them from the remote
location (or if not possible, move or rename them). I can't see how to
do it.


Any Sample Code for that ...


Thanks in Advance

With Regards,

Mani
Member
 
Join Date: Jul 2007
Posts: 37
#3: Jan 2 '09

re: Delete a file in Web Share C#


Use java script..

Hope following code will work for u...

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3.   myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
  4.   file = myActiveXObject.GetFile("c:\\test.txt");
  5.   file.Delete();
  6. // -->
  7. </SCRIPT>
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#4: Jan 2 '09

re: Delete a file in Web Share C#


That's really not an answer to the question.

I'm not sure what you mean by a "web share". If it's just a directory on a web server...then no, you absolutely can't remotely delete files. If you have FTP access, you can.

EDIT:
I've merged your posts. Please don't double post your questions.

MODERATOR
Newbie
 
Join Date: Oct 2008
Location: Coimbatore
Posts: 29
#5: Jan 4 '09

re: Delete a file in Web Share C#


hi ,
this is mani

i found out that solution using HTTP Webrequest can do this ...

Uri serUri = new Uri(URL);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(serUri);
System.Net.WebRequest.Create(serUri);

//long fileSize = fi.Length;
NetworkCredential myCred = new NetworkCredential(Domain/username, password);
CredentialCache MyCredentialCache = new CredentialCache();
MyCredentialCache.Add(serUri, "Basic", myCred);
wr.Credentials = MyCredentialCache;

//Set the request timeout to 5 minutes.
wr.Timeout = 300000;
// set the request method
wr.Method = "DELETE";

//Send the request and get the response.
HttpWebResponse HttpWResponse = (HttpWebResponse)wr.GetResponse()
this is code to delete a file in Web share HTTP

With Regards

Mani
Reply