This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
After downloading from my FTP Server, and trying to overwrite that file with an updated one, I get an exception saying: "UnauthorizedAccessException was handled", that, Access to the Path 'C:\My Program\My Program\bin\Debug\App_Data' is denied.
This is what my code looks like:
private void downloadFile () {
WebClient wc = new WebClient();
wc.Proxy = null;
wc.Credentials = new NetworkCredential("user", "pass");
byte[] fileData = wc.DownloadData("ftp://user:pass#mysite.tk/updates/App_Data/log.txt");
File.WriteAllBytes(Application.StartupPath + "\\App_Data", fileData);
}
Am I just missing something to set into the WebClient instance that can allow the 'File.WriteAllBytes' to write the file I'm downloading from my FTP Server to my local machine?
If you think about it, this obviously has nothing to do with WebClient. If you took the same sequence of bytes that you got from WebClient, and tried to write it to the same file, you'd get the same result.
In fact, you'd probably get the same result if you tried to write a single byte, and maybe zero bytes.
Like the exception says,
Access to the Path 'C:\My Program\My Program\bin\Debug\App_Data' is denied
Does the App_Data folder even exist?
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
How can I get complete querystring in asp.net?
Suppose a QueryString like this passed to my Login Page.
login.aspx?redirect=cart.aspx&p=1&q=2&r=3
I have to pass parameters p,q and r to Cart.aspx with all of the parameters except redirect.
Login.aspx may handle different querystrings but all parameters except the redirect are to be passed to the redirecting page.(Actually, I know there will be a parameter 'redirect' but can't write code for p,q,and r bcoz it may change in different contexts)
The parameters except 'redirect' will be different in different contexts. The p,q,r are required parameters for cart.aspx. If the redirection is to another page then the parameters may not be p,q,r instead something else like l,m,n
You can use like this
Request.Url.Query
Input like this
Input: http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment
Output
You can get the parameters using
string _url=Request.RawUrl.toString();
and
For path ...
string _path = Request.Path.ToString();
string _url = Request.ServerVariables["URL"].ToString();
O/P = /Home/About/
RawURl Returns whole querystring....
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I want to use the DownloadFile function of webclient but I used breakpoint to see which line O got error. It just go to catch block when DownloadFile.
try
{
string myStringWebSource = this.curFtpIp + FtpCuPath + "/" + FtpdfName + "/" + this.lbl.Text;
WebClient client = new WebClient();
client.Credentials = new NetworkCredential(this.FtpUserID, this.FtpPassword);
client.DownloadFile(myStringWebSource, SaveFile);
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
finally { }
I have solved my own question. I found that I set the wrong second parameter. I just use "SaveFile" which is save path but it should be a file name. So, I just modified the SaveFile and it can work.
WebClient.DownloadFile MSDN
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code:
'Files' is a List<string> and _indx is an int.
label22.Text = files[_indx];
For example in 'files' in index[0] I have this string:
D:\New folder (45)\converted.avi_Automatic\Lightning 0 Length 2 [91 - 93]\000091.bmp
But instead in label22.Text I want it to show me only '000091.bmp' without the rest of the directory path.
How can I do it ?
Use Path.GetFileName:
label22.Text = Path.GetFileName(files[_indx]);
I believe you are looking for Path.GetFileName():
label22.Text = Path.GetFileName(files[_indx]);
Path.GetFileName(fileName) returns the file name without the directory.
taken from http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.100).aspx
The simplest way is
Path.GetFileName(files[_indx]);
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm trying to save a file to the server and then load into a reader for it to be downloaded. However, I am getting a FileNotFoundExeption. I save to the exact same path, manually open the directory and can see the file there. However, reading it results in the exception. This is my first time trying his - am I doing something wrong?
try
{
using (StreamReader reader = new
StreamReader(HttpContext.Current.Server.MapPath(#"~/Downloads/data.text")))
{
// do something
}
}
catch (Exception)
{
}
Double-check the file name! In one of your comments you used the file name data.txt and not the name data.text. I suppose it's just a typo in your code.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
My final goal is to write a simple program for myself. It should periodically checks the Thinkpad online store, and will send me an email if it finds any products meeting my criteria.
I've done some research. To get the content of a webpage I can use the code
WebRequest request = WebRequest.Create("http://www.google.com");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
However for the online store website, I am not able to get the url of my desired page. The website url is in such format
http://outlet.lenovo.com/SEUILibrary/controller/e/outlet_us/LenovoPortal/en_US/catalog.workflow:expandcategory?current-catalog-id=A4A41B4CA13D4754AE2FB1EBF357¤t-category-id=908B184AED4F29502E6EB3E1E76AFC13&menu-id=products&ref-id=products#/?page-index=1&page-size=10
I filter the result to only display New W series laptop, but the filter changes doesn't affect the url in the browser address bar. What should I do?
To get anywhere, you should analyze the AJAX calls to the Lenovo Website (using Firebug or Chrome Developer Tools is a good start).
There you see that filter requests are sent to
http://outlet.lenovo.com/SEUILibrary/controller/e/outlet_us/LenovoPortal/en_US/catalog.workflow:GetCategoryFacetResults?q=1
then you'll need to POST some form data to that URL in order to get filtered results (which come back in HTML and you'll have to parse that somehow).
All this you can do by analyzing the AJAX calls.