I have a javascript file as an embedded resource in an assembly, and I'm trying to use the Stream from "System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("someName");" to create a new FileInfo object. My confusion is how to use a stream to create the FileInfo. If anyone can help me in this I would be greatly appreciative. I'm sure it's probably something easy, but easy is usually what I always seem to miss.
+2
A:
You can't. Because you have a Stream, and FileStream inherits from Stream, it doesn't mean that all Stream instances are FileStream instances (and by extension, have files that are the source of the Stream).
That being said, it doesn't make sense that the Stream returned from the call to GetManifestResourceStream would have a FileInfo associated with it, just like a NetworkStream wouldn't have a FileInfo instance associated with it either.
casperOne
2010-03-02 19:53:41
+1
A:
You have to create the file, then read the resource stream, and write the file stream.
John Saunders
2010-03-02 19:58:21
So then I want to create the new File using something like File.Create("pathToFolder"). Then use a Writer to write the stream to the file.
jhorton
2010-03-02 20:04:12
Or else just do your own inputStream.Read / outputStream.Write loop.
John Saunders
2010-03-02 20:10:15
+1 for answering the question behind the question.
Erik Forbes
2010-03-02 20:18:29
So to clarify after a successful write. I had to use a StreamReader for the EmbeddedResource stream, and a StreamWriter for the new FileStream. Very basic skills that have seemed to leaked out of my metaphorical cracked glass.
jhorton
2010-03-03 13:52:52
A:
If you really need a FileInfo, then you'll probably have to copy the data from your embedded resource out to a file on the file system. This question has some sample code.
Don Kirkby
2010-03-02 20:05:01