Im working on a project which i need to download a magnet link from torrent websites. For example i give the magnet link to a text box and it downloads the content of that magnet link in the specified folder.
I wanted to use monotorrent but it was very complicated and it actually didnt work and it just throw some errors and one of them was "URI prefix is not recognized" and didnt know how to solve it.
and again, all i want to do is to download the magnet link and maybe show the progress with the progress bar
How can I implement such a program with C#?
Using Process.Start() will open the magnet URL with the default application set for handling them. It won't open in your application, but then you'd be writing a torrent application (which is not the easiest task...):
string magnetUrl = "magnet:?xt=urn:sha1: ..."
Process.Start(magnetUrl);
The best way would be programmaticaly downloading torrent file and then run a program with parameter which is the path to torrent file. For example you could use cygwin with rtorrent (command-line torrent client)
Related
I tried to use few method to download 1 excel file from website
I tried to use WebClient and DownloadFile... but it return 400 bad
request
I tried to use File.WriteAllBytes also kick in exception
My current workaround is call IExplorer with that particular file path ..then it will start to download(after user select file path)
Is that any way that i can straight download excel file without any notification?
Sample Excel Link: https://example.com/sr/XXX.issueviews:searchrequest-excel-all-fields/12345/SearchRequest-12345.xls?tempMax=1000
I want to open Documents from Shared Folder on network using ASP.NET with C#.
My situation as follow:
My Web Server Name is “WebServer1” use IIS 7
My DC Server Name is “DC1”
My File Server Name “FileServer1”
My Files Path
\\FileServer1\A\B\C\MyDoc.docx and \\FileServer1\A\B\C\MyPDF.pdf
I tried the following
1- I Created Hyper Link
link to file
The files open on some machines that uses Internet Explorer version 8 but on any other version or Chrome, Fire Fox, or any other web browser it doesn't work when I click on the hyper link no action happens and no errors, but if I copied the link address and pasted it into the web browser the file opens
I gave the path in the file server full control permission for “everyone”
2- I also tried to create a button with the following code
Response.ContentType =
"application/vnd.openxmlformats- officedocument.wordprocessingml.document";
Response.AppendHeader("Content-Disposition", "attachment; filename=5401-1-2289.docx");
Response.Redirect("file:///// FileServer1\A\B\C\MyDoc.docx");
Response.Flush();
First of all, the URL is incorrect. It should be #"file://\\FileServer1\A\B\C\MyDoc.docx" instead of "file:///// FileServer1\A\B\C\MyDoc.docx" (I have a hard time thinking this actually compiles, because you didn't escape \...)
Second, you are combining both sending content, as redirecting, as pointed out by Luaan in a comment. This won't work.
You could transmit the file directly. This also prevents you to expose your network drive to external users:
Response.TransmitFile(#"\\FileServer1\A\B\C\MyDoc.docx");
I am having problem in asp.net. Actually I am letting my website's visitor to install an window application from that web site. I have added my application without creating installer so it is just an .exe file which is showing a normal form. But the problem is when user tries to download that file an error message is being shown that says that "This file can harm your computer. Do you want to keep this file anyway?" So I don't want to display that message. can you please help me out. Thanks in advance.
This is neither a "problem" of ASP.NET nor the WinForms application. This is a thing that modern browsers do when you download an application or document that might contain (potentially malicious) executable parts. If there was a "this thing won't harm anybody"-flag for downloads, do you think that this would only be set by "nice" developers?
You can try ActiveX to download file from internet explorer browser. This might help. The way to make download in given below.
Example:
public class Downloader
{
public void DownloadFile()
{
using(WebClient webClient = new WebClient())
{
webClient.DownloadFile("http://www.stackoverflow.com/stacks.txt", #"c:\stacks.txt");
}
}
}
I am showing a list of hyperlinks on a web page that are intended to open windows explorer at the folder containing the file. The file paths are stored in a database and retrieved.
If the file path in question is showing in my C# code as \\\\myserver\\folder1\\somedocument.doc
I can set the href of the hyperlink to be: file://\\\\myserver\\folder1 and it works. Windows Explorer opens and shows the contents of folder1.
But, if the user who originally specified the file, selected one on his C:\ drive, I might have a path like this to deal with C:\\Somefile.txt
In this case I want to format the hyperlink so that it opens Windows Explorer and shows the contents of the C: drive. How can I do this?
file:///C:/ would work. But note, that this is only working in Internet Explorer. Neither Chrome, nor Firefox support such a behaviour. (Chrome and Firefox will list the drive's content in the browser instead of opening Windows-Explorer)
There are extensions for chrome, but i dont think, that this is what you are looking for.
It should work just the same as a network path. Have you tried file://c:\?
Other users will not be able to see that file of course, only the one that submitted it.
file:///c:/ should work for this
To open C:\ by default you can use: "explorer.exe /e,C:\"
Same syntax applies to fileshare: "explorer.exe /e,\myserver\folder1"
How can I get the path of a file on my computer or on the local area network.
I would to show a window that allows me to browse the file system when I click a button, and I want to select a file and get the path to the file. How can I do this?
P.S. I'm not looking to upload the file; I just want to get the path.
The web application is running on the server, and you don't have access to the client file system at all. Can you imagine how much of a vulnerability that would be? I know I don't want the sites I visit inspecting my file system...
EDIT: Question is for a WinForms application
For a WinForms application, you can use the OpenFileDialog, and extract the path with something like this:
If you're looking for the file path:
string path = OpenFileDialog1.FileName; //output = c:\folder\file.txt
If you're looking for the directory path:
string path = Path.GetDirectoryName(OpenFileDialog1.FileName); //output = c:\folder
In general, the System.IO.Path class has a lot of useful features for retrieving and manipulating path information.
To do this in VB.NET use the FolderBrowserDialog.
Due to security restrictions browsers include for user safety, you can't manipulate the client file system directly. You can only use to let them pick a file, and even then it only sends the filename, not the whole path.
The FileSystem API in HTML5 allows for file manipulation, but only within a sandbox for your site specifically, not browsing across the network or other files on the client system.
Instead, provide your users easy steps on how they should use My Computer (or whatever equivalent on other OS's) to navigate to the file and copy & paste the path into a simple text input box.
Have you taken a look at the Path class from System.IO ?