Answered by:
fileupload in a server control?

Question
-
User-334574633 posted
Hello,
I cant seem to get the uploaded file inside my server control dll file, first i create a controls httpupload and a button, the sends it to the client inside CreateChildControls(), question is, where do i capture the respons? What function do i override to get the actual posted file??
Below is the createchildcontrol function that i use to create the upload form for the user.
FileUpload mUpload;
protected override void CreateChildControls()
Button mButton;
{
this.Controls.Clear();
this.mUpload = new FileUpload();
this.mUpload.ID = "fileInput";
this.Controls.Add(mUpload);this.mButton =
new Button();
this.mButton.ID = "btnFileUpload";
this.mButton.Text = "Upload";
this.Controls.Add(mButton);
}Here i need to capture the uploaded file somehow.
Patrick
Saturday, May 31, 2008 12:44 PM
Answers
-
User-627724879 posted
It is sent to the server as part of the Request Object, look at the code in the ASP.NET FileUpload control.
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public HttpPostedFile PostedFile { get { if ((this.Page != null) && this.Page.IsPostBack) { return this.Context.Request.Files[this.UniqueID]; } return null; } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 31, 2008 3:19 PM
All replies
-
User-627724879 posted
It is sent to the server as part of the Request Object, look at the code in the ASP.NET FileUpload control.
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public HttpPostedFile PostedFile { get { if ((this.Page != null) && this.Page.IsPostBack) { return this.Context.Request.Files[this.UniqueID]; } return null; } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 31, 2008 3:19 PM -
User-16411453 posted
This works too and handles the event args
Change to protected override void OnInit() 'there is an event arg in the ()
Saturday, May 31, 2008 7:06 PM -
User-334574633 posted
It is sent to the server as part of the Request Object, look at the code in the ASP.NET FileUpload control.
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public HttpPostedFile PostedFile { get { if ((this.Page != null) && this.Page.IsPostBack) { return this.Context.Request.Files[this.UniqueID]; } return null; } }
protected
override void OnLoad(EventArgs e)
{
if (mUpload.HasFile)
{
Response.Write(mUpload.FileName + "<br />");
}
}If i add 1 more fileupload control and use mUpload2.HasFile, it will print the same file name as mUpload.
Patrick
Sunday, June 1, 2008 6:39 AM -
User437720957 posted
If i add 1 more fileupload control and use mUpload2.HasFile, it will print the same file name as mUpload.
I think you have mistyped something, because that should work just fine.
Sunday, June 1, 2008 2:05 PM -
User-627724879 posted
Yes it should work just fine. You see it takes the UniqueId of the FileUpload control. If you look for that you should be fine.
Sunday, June 1, 2008 10:18 PM