Pass file as parameter

  • Thread starter Thread starter Remote_User
  • Start date Start date
R

Remote_User

Hi,
Is there any way I can pass a file as a parameter? ( maybe read it
into a object) I am working on C# VS2005.

Thanks.
 
The easiest option would be to pass the path (as a string), and let
the method worry about what to do with it. But you might choose to
pass a Stream, or a reader (TextReader, XmlReader, etc).

So; what exactly is the file? And from where are you passing it? i.e.
there will be different answers depending on whether the caller is
regular .NET vs COM interop vs ASP.NET etc.

Marc
 
Remote_User said:
Hi,
Is there any way I can pass a file as a parameter? ( maybe read it
into a object) I am working on C# VS2005.

Thanks.

No, you can't pass a file as a paramter.

You can pass the contents of a file as a byte array.
You can pass the path of a file as a string.
You can pass a FileInfo object that contains information about the file.
You can pass a FileStream opened against a file.
You can pass a StreamReader that reads an open FileStream.
 
All, Thanks for the reply.

Yes so it's a regular .NET app and I don't want to FTP it. Looks like
I need to send the contents of the file in a byte array as the only
option. Does that affect my performance in case the file size is a bit
large?

Thanks.
 
Does that affect my performance in case the file size is a bit
Yes big files as byte[] is a problem - either it'll eat all the
memory, or it'll simply break; and no, that isn't the only option;
every other option we've mentioned would, in fact, be preferable to a
byte[], which is very limiting. Stream being the most generic...

Marc
 
Remote_User expressed precisely :
All, Thanks for the reply.

Yes so it's a regular .NET app and I don't want to FTP it. Looks like
I need to send the contents of the file in a byte array as the only
option. Does that affect my performance in case the file size is a bit
large?

Thanks.

When you have a byte[] as parameter to a method then not the entire
array is copied when you call that method: just the *reference* to that
array is passed.
So memory use / performance hit is only in loading the file into the
array, not in passing the (reference to the) array to the method.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top