Sending A File As A Method Argument?
12,664
It depends what you need to do with it :)
Options include:
- path (string)
- contents (string or byte[])
- some complex object model (od your own choosing) of the contents
- FileInfo
- FileStream (or just Stream)
- some kind of reader/writer; TextReader, XmlWriter etc
Author by
sooprise
I like to program, but am a noob, which is why I'm here. <-My sexy fatbooth picture
Updated on June 04, 2022Comments
-
sooprise about 2 years
Is this sort of thing possible:
public static void DoThis(file aFile){ //Blah blah blah }
-
Muad'Dib over 13 years@Marc Gravell an instance of a class of the type "file"
-
Brian over 13 yearsC# will allow you to pass a handle to a file using
IntPtr
orSafeFileHandle
. However, that's a bit low level and mainly is only useful for interop. See stackoverflow.com/questions/3562513/… for discussion. -
Brian over 13 years@Muad'Dib: As
file
is not part of the framework, your answer strikes me as begging the question. -
Muad'Dib over 13 years@Brian the OP supplied the paramaters, and it was his/her code that i was using.
-
Brian over 13 years@Muad'Dib: But since the OP was asking, "Is this sort of thing possible?" your answer doesn't provide any information on how to make it possible. As the title indicates, the OP's underlying question is how to send a file as a method argument. The code is an example of the syntax he hopes to use.
-
Muad'Dib over 13 years@Brian and the OP doesn't say it is a System.IO.File or some custom class, he just asks if it is possible. and, as we know, it is.
-
BornToCode over 10 yearsIf it's a posted file (from HTML input field) you could also pass the file as a
HttpPostedFile
(its class is in System.Web.dll) -
floydheld almost 3 yearsmaybe a short example for each option?