|
-
Sep 2nd, 2018, 03:05 PM
#1
Thread Starter
New Member
How can I extract a torrent file from my resources ? (Resolved)
Last edited by o0NT210o; Sep 3rd, 2018 at 04:18 PM.
-
Sep 2nd, 2018, 08:12 PM
#2
Re: How can I extract a torrent file from my resources ?
Firstly, SaveFileDialogs and Buttons are irrelevant.
If you want to save a file then you need a path to save it to. The SaveFileDialog simply provides a way for the user to provide that path but the path is just a String in the end. When you save the file you provide the path as a String. Whether that String is hard-coded or comes from the FileName property of a SaveFileDialog is irrelevant to the action of saving the file.
If you want to save a file - or do anything at all - then you need to start from an event handler. Windows Forms is event-driven, meaning that all actions start by an object raising an event and invoking an event-handler method and you putting some code to execute in that method. Whether the event is the Load of a Form, the Click of a Button, the Tick of a Timer or something else is irrelevant to the code being executed.
So, it appears that you have added this file to your resources on the Resources page of the project properties. That's good. You now access the data from the file (the file itself no longer exists as far as the app is concerned; a resource is data, not a file) via a property of My.Resources. Which data type that property is depends on the type of file you started with. If you started with a text file then the property will be type String. For most file types, the data type will be either Byte(), i.e. Byte array, or UnmanagedMemoryStream. The way you save that data to a file depends on that data type. You can find out what that data type is easily with the help of Intellisense. You can type this code:
vb.net Code:
Dim x = My.Resources.SomeResource
and then mouse over the 'x' variable and Intellisense will tell you what data type is. It will even give you the type of the property before you finish typing that code.
Here is how you can save text, a Byte array or an UnmanagedMemoryStream to a file:
vb.net Code:
File.WriteAllText(filePath, My.Resources.TextResource) File.WriteAllBytes(filePath, My.Resources.ByteArrayResource) Using inputStream = My.Resources.StreamResource, outputStream = New FileStream(filePath, FileMode.Create) inputStream.CopyTo(outputStream) End Using
Note that that code to save the file is, again, independent of the fact that you're using resources. File.WriteAllText is the way you save ANY String to a file, File.WriteAllBytes is how you save ANY Byte array to a file and Stream.CopyTo to a FileStream is how you save ANY Stream to a file. This is why you need to break your problem down. If you look for information on how to save resources to files then you're severely limiting the information you can use and you'll miss plenty of relevant information. Saving a resource to a file is two steps: getting data out of the resource and saving data to a file. ANY information on saving data to a file is relevant because it is independent of the source of the data. ALWAYS divide and conquer, i.e. break your problem up into parts, attack each part separately and then combine your partial solutions.
Last edited by jmcilhinney; Sep 2nd, 2018 at 08:18 PM.
-
Sep 3rd, 2018, 04:15 PM
#3
Thread Starter
New Member
Re: How can I extract a torrent file from my resources ?
Thank you very much, It work now !
-
Sep 3rd, 2018, 04:16 PM
#4
Thread Starter
New Member
Re: How can I extract a torrent file from my resources ?
Thank you very much, It work now !
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|