Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hej Guys,
Have a really basic task here...
I have a blank new UserControl - where I have simple asp:FileUpload control...
What I want is - upload actual file to the server. And save it there.
Then if I need it, it should have a url - that links to the document.
My problem is. when I am trying to use this
string fileName = fileUpload.FileName;
As a result - I end up having string value, that links to no file, because file was not actually uploaded.
My ultimate goal is to make a control that can do the same thing as "upload" Document type property
I want to make 1 like this myself programatically.
Any suggestions how to do something like this?
Hey Dmitrij,
looks like you are looking for regular .NET functionality.
You would need a button to trigger the actual upload of the file.
So your ascx could look like this:
<asp:FileUpload ID="OurUmbr_FileUpload" runat="server" /> <asp:Button ID="OurUmbr_UploadButton" runat="server" Text="Upload file" OnClick="OurUmbr_UploadButton_Click" /> <asp:Label ID="OurUmbr_UploadStatusLabel" runat="server" />
And codebehind could look like:
protected void OurUmbr_UploadButton_Click(object sender, EventArgs e) { if (!OurUmbr_FileUpload.HasFile) return; try { var filename = Path.GetFileName(OurUmbr_FileUpload.FileName); OurUmbr_FileUpload.SaveAs(Server.MapPath("~/") + filename); OurUmbr_UploadStatusLabel.Text = "Upload status: File uploaded!"; } catch (Exception ex) { OurUmbr_UploadStatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } }
This should do the trick.
Take care,
WD
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
File upload through custom user control
Hej Guys,
Have a really basic task here...
I have a blank new UserControl - where I have simple asp:FileUpload control...
What I want is - upload actual file to the server. And save it there.
Then if I need it, it should have a url - that links to the document.
My problem is. when I am trying to use this
As a result - I end up having string value, that links to no file, because file was not actually uploaded.
My ultimate goal is to make a control that can do the same thing as "upload" Document type property
I want to make 1 like this myself programatically.
Any suggestions how to do something like this?
Hey Dmitrij,
looks like you are looking for regular .NET functionality.
You would need a button to trigger the actual upload of the file.
So your ascx could look like this:
And codebehind could look like:
This should do the trick.
Take care,
WD
is working on a reply...