Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The site provides links as http://www.example.com/download.php?id=53979 . I know that this is a pdf file and want to download it via a C# program. Is this possible and if yes, how?
In order to download a file, you simply need to use the WebClient object like in the question referenced above:
using (var client = new WebClient())
client.DownloadFile("http://www.datasheet4u.com/download.php?id=53979", "datasheet.pdf");
What makes your case slightly different has nothing to do with the server being written in PHP or anything like that. The link you provided (http://www.datasheet4u.com/datasheet/L/M/7/LM741_NationalSemiconductor.pdf.html) appears to be checking Referer headers when serving the file. This is likely some attempt on their part to prevent what you're trying to do, but it doesn't actually prevent it.
All you need to do is add a Referer header to the request. Something like this:
using (var client = new WebClient())
{
client.Headers.Add("Referer","http://www.datasheet4u.com/datasheet/L/M/7/LM741_NationalSemiconductor.pdf.html");
client.DownloadFile("http://www.datasheet4u.com/download.php?id=53979", "datasheet.pdf");
}
The method for downloading the file is still the same. The server just requires that you send an extra piece of information in the request.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want have my azure . NET web application upload a file, manipulate it and then download the changed version.
Should I use blob storage? I don't actually need to store the data in the file.
Should I use blob storage?
That depends on what your requirements are.
I don't actually need to store the data in the file.
Given this fact, you probably don't need to use blog storage.
You could simply do something like this:
var postedFile = Request.Files[0] as HttpPostedFileBase;
var stream = new MemoryStream();
postedFile.InputStream.CopyTo(stream);
// work with MemoryStream
...
//return your file which could be different based on mvc, web forms or whatever
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Long explanation made short, I NEED to supply a proper user agent when posting data to my server; Why? I don't know entirely.
In any case, I've read that making a web request prior and grabbing the header from it would suffice, but I'd like to know if there's a more cleaner/sufficient method.
You can indeed just grab one from your favourite browser, or pick one from here.
The user agent string is just that - a string containing various info about the browser. So it's just a matter of passing it along with you request. If your program will live for a while, I'd try to pick one that's as generic as possible.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to read in a .cs file from my project which contains a code sample for use by clients of my company's API.
What's the best way to read in this file and pretty-print it to the page with indentations etc. The goal is to just have the code on the page automatically change when I update the contents of this file so that the code sample will always be up to date as published on the live site.
An example of what I'm attempting to accomplish is something similar to this: http://msdn.microsoft.com/en-us/library/vstudio/ezwyzy7b.aspx
I'd use this...
http://www.manoli.net/csharpformat/
http://www.manoli.net/csharpformat/CSharpFormat.zip
It transforms C# code into html. You can read the file run it through the CSharpFormat then output the HTML to a panel in the page.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to extract a text file located on a remote computer to my computer using c# programming language.
How can I do it?
I tried using file.copy method, but was unable to do it.
Can anyone suggest some other method.
Thanks in advance
If you're using C# with file.copy you have to have the remote drive mapped to your computer and you have to be authenticated. I'm betting the problem you are having is simply related to the fact that you don't have permission to get the file you are trying to get.
If you have a valid username/pw for the remote machine, map the drive:
http://windows.microsoft.com/en-us/windows/create-shortcut-map-network-drive#1TC=windows-7
If you still have issues it's likely something on the remote machine stopping you.
Edit:
If you are attempting to access a drive on the same network attempt to visit the URI in windows explorer. If you can get to it than there is another issue entirely. If you cannot get to it or if it asks for user or PW you simply don't have permission to be there.
Edit 2:
Pro-tip: Avoid trying to look like you are attempting to "hack" something. I guarantee you you will be flamed and down-voted to oblivion as obvious by the other responses you've gotten.
EDIT 3:
Another stack overflow article talking about the same thing with c#
Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to know how to send C# array to php web service .
here c# application is in client and php webpage is in server,this php web service get that array and store in database
you cannot directly send array to php service but what you can do is create a string separated by ','(coma) & then send it in url or as response,
at server side you can just split it & here you get your ans.
Another way is as Elliot said but you need some JSON knowledge.
You must:
Convert your data to JSON or XML using serialization (according to what your service consumes).
Create HTTP POST Query, look at MSDN for classes for doing it.
Put your converted data in the query body.
Send it.