How do I pass a file to a class?

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,

I have a web form I use to allow users upload files to the web server.
Instead of handling this operation in the code behind of the web form, I
want to create a class that contains document management functions in it.
However, I don't know how to pass the file to this class. I'd appreciate
some pointers on how to do this.

Here's where I am stuck

public static int DumpFileOnWebServer( -- I don't know what goes in here --)
{
// Once I know how to pass the file to this class
// I can go ahead and handle the process in here i.e. where to put the
file, etc.
}

Thanks for your help.

Sam
 
Sam,

You can pass an instance of the HttpFilesCollection class, which
contains the information about all of the files that were uploaded to your
page. This is exposed by the Files property on the HttpRequest class.
Because you might need extra information that is part of the request, you
might want to consider passing the HttpRequest itself, which would have all
of the information in it, or even the current HttpContext, which exposes the
Request, the Response, the Application, Server, etc, etc.

Hope this helps.
 
Hi Nicholas,

Would you be nice enough to point to a code sample on a web site? Thank you
very much.


Sam


Nicholas Paldino said:
Sam,

You can pass an instance of the HttpFilesCollection class, which
contains the information about all of the files that were uploaded to your
page. This is exposed by the Files property on the HttpRequest class.
Because you might need extra information that is part of the request, you
might want to consider passing the HttpRequest itself, which would have all
of the information in it, or even the current HttpContext, which exposes the
Request, the Response, the Application, Server, etc, etc.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

Sam said:
Hi,

I have a web form I use to allow users upload files to the web server.
Instead of handling this operation in the code behind of the web form, I
want to create a class that contains document management functions in it.
However, I don't know how to pass the file to this class. I'd appreciate
some pointers on how to do this.

Here's where I am stuck

public static int DumpFileOnWebServer( -- I don't know what goes in here --)
{
// Once I know how to pass the file to this class
// I can go ahead and handle the process in here i.e. where to put the
file, etc.
}

Thanks for your help.

Sam
 
Hi Sam, Nicholas,

I would do otherthing instead, I would upload the file using the code
behind and later provide this local file to the Doc. management layer.

You could upload the file to a temp file and later delete if needed.

Just my 2 cents :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nicholas Paldino said:
Sam,

You can pass an instance of the HttpFilesCollection class, which
contains the information about all of the files that were uploaded to your
page. This is exposed by the Files property on the HttpRequest class.
Because you might need extra information that is part of the request, you
might want to consider passing the HttpRequest itself, which would have all
of the information in it, or even the current HttpContext, which exposes the
Request, the Response, the Application, Server, etc, etc.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

Sam said:
Hi,

I have a web form I use to allow users upload files to the web server.
Instead of handling this operation in the code behind of the web form, I
want to create a class that contains document management functions in it.
However, I don't know how to pass the file to this class. I'd appreciate
some pointers on how to do this.

Here's where I am stuck

public static int DumpFileOnWebServer( -- I don't know what goes in here --)
{
// Once I know how to pass the file to this class
// I can go ahead and handle the process in here i.e. where to put the
file, etc.
}

Thanks for your help.

Sam
 
Back
Top