By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Delete a file in Web Share C#

Manikgisl
P: 37
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
Jan 2 '09 #1
Share this Question
Share on Google+
4 Replies


Manikgisl
P: 37
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
Jan 2 '09 #2

P: 37
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>
Jan 2 '09 #3

Curtis Rutland
Expert 2.5K+
P: 3,256
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
Jan 2 '09 #4

Manikgisl
P: 37
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
Jan 4 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.