0

I am creating webpart to upload file. I created asp button:

<asp:Button ID="txtUpload" runat="server" Text="Upload" OnClick="txtUpload_Click" />

Then on click event of button i write

FileUpload fileUpload = new FileUpload();

But i dont get any fileopen dialog. I also wish to add filter to only select images. How can we do it? After selecting i want to upload to sharepoint document list as attachment

Update1

I have found this example link but i want it without textbox and browse button. I just want to open file dialog on click of my button

1 Answer 1

0

try below code

<asp:FileUpload id="FileUploadControl" runat="server" /> <asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />

to upload use below code in the event

string filename = Path.GetFileName(FileUploadControl.FileName);
        FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
        StatusLabel.Text = "Upload status: File uploaded!";
3
  • But this will display textbox and browse button Commented May 7, 2015 at 5:51
  • I don't think there is any way to open dailog for files as you wish to implement, you can try hiding the textbox and keep the button visible. Commented May 7, 2015 at 5:57
  • Can u tell how to hide textbox? Commented May 7, 2015 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.