Copy file via reasources
Page 1 of 111 Replies - 249 Views - Last Post: 10 February 2012 - 06:56 AM
#1
Copy file via reasources
Posted 08 February 2012 - 03:55 AM
Replies To: Copy file via reasources
#2
Re: Copy file via reasources
Posted 08 February 2012 - 06:45 AM
A quick search found this result.
Basically all you're doing is getting it from the resource, opening it with a streamreader and then using streamwriter to write it back to your path & filename.
This post has been edited by CharlieMay: 08 February 2012 - 06:46 AM
#3
Re: Copy file via reasources
Posted 08 February 2012 - 06:53 AM
CharlieMay, on 08 February 2012 - 06:45 AM, said:
A quick search found this result.
Basically all you're doing is getting it from the resource, opening it with a streamreader and then using streamwriter to write it back to your path & filename.
Wow this might be a really stupid question but how do i get this to work? The website just gives the coding to a module.But what do i do with it?
I am not trying to make someone do my homework for me but i genuinely don't know what to do with the module.Could you make a sample project and show me.
Again.I am not trying to make you do my homework,i am just clueless right now.
A sample project would be immensely appreciated.
#4
Re: Copy file via reasources
Posted 08 February 2012 - 07:09 AM
Just make sure you don't forget the imports at the top of your code.
#5
Re: Copy file via reasources
Posted 08 February 2012 - 08:53 AM
CharlieMay, on 08 February 2012 - 07:09 AM, said:
Just make sure you don't forget the imports at the top of your code.
I still get an error in the line
Using input As New StreamReader(source)
It says "Value cannot be null.
Parameter name: stream"
What am i doing wrong?
#6
Re: Copy file via reasources
Posted 08 February 2012 - 09:16 AM
Quote
#7
Re: Copy file via reasources
Posted 09 February 2012 - 09:54 AM
CharlieMay, on 08 February 2012 - 09:16 AM, said:
Quote
How do i set the Build Action for the file to "Embedded Resource" ?
I am confused? is this under properties?
#8
Re: Copy file via reasources
Posted 09 February 2012 - 10:55 AM
#9
Re: Copy file via reasources
Posted 10 February 2012 - 01:55 AM
CharlieMay, on 09 February 2012 - 10:55 AM, said:
Brilliant! worked like a charm.Thank You
I have one last question, How do i modify the code so that the user can copy the textfile to any directory he wants to instead of the textfile copying itself automatically to the installation directory.
Could this be done with a Savefiledialog? if so what modifications should i add to the coding.
#10
Re: Copy file via reasources
Posted 10 February 2012 - 05:00 AM
#11
Re: Copy file via reasources
Posted 10 February 2012 - 05:38 AM
CharlieMay, on 10 February 2012 - 05:00 AM, said:
I am a newbie,i get an error when i try it.I haven't learnt any of these.I get an error
Dim currentAssembly As Assembly = Assembly.GetExecutingAssembly()
Dim streamName As String = "TextFile1.txt"
Dim contents As String
Using source As Stream = currentAssembly.GetManifestResourceStream(GetType(Form1), _
streamName)
Using input As New StreamReader(source)
contents = input.ReadToEnd()
End Using
End Using
Using output As New StreamWriter("file.txt")
SaveFileDialog1.ShowDialog()
output.Write(SaveFileDialog1.FileName)
End Using
End Sub
What am i doing wrong?
#12
Re: Copy file via reasources
Posted 10 February 2012 - 06:56 AM
Also, there should be a variable that holds what the dialog returned (String).
Have you researched how to use the SaveFileDialog, there is an example in the MSDN page that is very clear cut.
|
|

New Topic/Question
Reply



MultiQuote




|