Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I looking for a code to remove images from FTP but does'nt work
I tried to use this code but not work for me:
Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://myftpname.es/Html/images/" & imagename), System.Net.FtpWebRequest)
FTPRequest.Credentials = New System.Net.NetworkCredential("FTPUsername", "FTPPassword")
FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
FTPRequest.UsePassive = True
FTPRequest.UseBinary = True
FTPRequest.KeepAlive = False
How can I remove images from ftp?
Thanks
this code not remove the image from the ftp
That's because you never actually execute it, you just initialize it. To issue a WebRequest, you need to get its response:
var response = FTPRequest.GetResponse()
Have you tried using the FtpClient class?
Dim client as new System.Net.FtpClient.FtpClient()
client.Credentials = new NetworkCredential("FTPUsername", "FTPPassword")
client.Host = "ftp://myftpname.es"
client.Connect()
client.DeleteFile("Html/images/" & imageName)
Related
This question already has answers here:
C# WebClient disable cache
(12 answers)
Closed 7 years ago.
I am using this code to get the return string from URL
webClient.Encoding = Encoding.UTF8;
response = webClient.DownloadString("http://somesite.com/code.php");
Console.Write(response);
the code.php looks like this
<?php
$data = file_get_contents('code.txt');
echo $data;
?>
The problem is when I change the contents of the code.txt file, the webClient.DownloadString() method returns the old contents of the code.txt file. When I open the URL http://somesite.com/code.php in a browser it works perfectly fine.
Any solutions will be appreciated!
My question seems to be duplicated but I don't really understand what is said here: C# WebClient disable cache
If anyone could explain and provide some example code it would be great!
Try disabling the cache on the WebClient
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
MSDN Documentation on WebClient Cache
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Currently working with Unity, this might a super basic question, but here goes.
I need to call a URL from my app in C#. This is done for analytics purposes, and so I don't want to open a web browser or anything, just call the URL and that's it. I know about Application.OpenURL() to open the browser, but how do I achieve this without opening the browser ?
You may try like this:
var client = new WebClient();
var x = client.DownloadString("http://example.com");
or
HttpWebRequest request = WebRequest.Create("http://example.com") as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
Use the WebClient class in the System.Net namespace.
It's a high level implementation of an HTTP client which is really easy to use.
Has a method called .DownloadString() which does exactly what you want - calls a URL using HTTP GET and returns the response as a string.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have developed a program which is sending HTML email using mail definition class.
Is it possible to preview the email before sending it.
Here is a piece of code using mailDefinition :
MailDefinition mailDefinition = new MailDefinition();
mailDefinition.BodyFileName = "C:/Html_Email.htm";
mailDefinition.From = "kami#gmail.com";
ListDictionary ldReplacements = new ListDictionary();
ldReplacements.Add("<%NearTeaser%>", "<b> Welcome to <b>" + nearteaser + "<b>");
ldReplacements.Add("<%Content%>", fulltext);
ldReplacements.Add("<%Weitere%>", "We have these offers for you: " + Weitere);
MailMessage mailMessage = mailDefinition.CreateMailMessage(mailTo, ldReplacements, new System.Web.UI.Control());
mailMessage.IsBodyHtml = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "hostname";
client.Send(mailMessage);
Every thing is working fine. I am curious if it is possible to preview the email before sending it.
Many thanks.
Before sending email display the contents of ldRelacements in a multitext box or in a panel/div.
MailDefinition class allows to create email messages from text files or strings.
Please go through http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.maildefinition(v=vs.110).aspx. It will give you some insights about MailDefinition class and examples.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This is my code. What am i trying to do is connect to webservice and download a file to a specific location.
Code throws an exception. Looks like i should retun some value to service before i download a file (not sure tho).
WebClient webClient = new WebClient();
NetworkCredential netCred=new NetworkCredential();
netCred.UserName="user";
netCred.Password="pass";
netCred.Domain="domain";
webClient.Credentials = netCred;
WebProxy wp = new WebProxy();
wp.Credentials = netCred;
wp.Address = new Uri(#"http://okolje.arso.gov.si/service/prevozniki.zip");
webClient.Proxy = wp;
webClient.DownloadFile("http://okolje.arso.gov.si/service/prevozniki.zip", #"C:\arso\prevozniki.zip");
you need to say what port your proxy is e.g.
webClient.Proxy = new WebProxy("127.0.0.1:8118");
you also have to actually set up this proxy, webclient.proxy just uses it, it doesn't create it
I'm not entirely sure what the rest of your code is doing, but I don't think you need the
wp.Address = new Uri(#"http://okolje.arso.gov.si/service/prevozniki.zip");
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C# Connecting Through Proxy
I've tried doing this for a long time in many different ways but nothing seems to work. Essentially I want to create a proxy checker in C# that checks it by actually going to a page (e.g. http://google.com/ncr) and determines from there if it got there or not.
Is this even possible?
If it is a http proxy
bool OK = false;
try
{
WebClient wc = new WebClient();
wc.Proxy = new WebProxy(Host, Port);
wc.DownloadString("http://google.com/ncr");
OK = true;
}
catch{}