SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to implement openfile dialog in a webpart ?
OpenFileDialog class could not be accessed in webpart.
Is there any other way to achieve this ? File Browse Dialog

share|improve this question
what exactly are you trying todo? open a file from a site? or save to a site? – ali Sharepoint Mar 25 '13 at 12:49
@aliSharepoint I want to upload a document to the site. The user should be able to browse the file. – Laxman Mar 25 '13 at 12:55
up vote 1 down vote accepted

ahh ok, your looking for fileupload:

Displays a text box control and a browse button that enable users to select a file to upload to the server.

This programming task shows how to upload a file from a local folder to a folder on a Microsoft SharePoint Foundation site. The task uses the EnsureParentFolder method to ensure that the destination folder exists.


i understand that your using a webpart instead of aspx page! but what you can do in aspx you can do in .cs , so in your case:

protected override void CreateChildControls()
    //create the textbox file object
    HtmlInputFile tbuploadfile = new HtmlInputFile();
    //add the newly created HtmlInputFile to the controls
    //when you run the code add it to the page you should see that new control

so just do the same as above for what its asking for in the aspx but convert it to .cs instead... its simple todo as above :) . wss 3.0 is a pain the *


scroll to the bottom of the page to show you how its done ;)

another option

share|improve this answer
Actually I dont have .aspx file in my project. In the second link it is specified to add HtmlInputFile to the form on .aspx page. I'm developing sharepoint webpart and my webpart inherits from System.Web.UI.WebControls.WebParts.WebPart. – Laxman Mar 25 '13 at 13:26
changed my answer, checkout the update :) – ali Sharepoint Mar 25 '13 at 14:12
hi, thanks for the update. I got it worked. :) – Laxman Mar 26 '13 at 7:40
glad to see you got it working – ali Sharepoint Mar 26 '13 at 9:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.