.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

FileUpload Control with membership and roles

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net

Hi Everyone!

I'm pretty new to development using Microsoft technologies.

I'm trying to build a portal kind of an application in asp.net, in which one of the functionality is letting people log in and upload their documents. The upload page is only accessible to registered users of the portal.


I would like to track the user uploaded files according to their userIds.

Is it possible to use the FileUpload Control and C# to fetch the current user id, create a directory with the same name(as that of userID) in the file system and upload the files( multiple file upload, if necessary) into it?

Also another admin page would have to be able to see the list of files uploaded by the specific user and download it if necessary.

Could anyone help me with this?

I'm also expecting alternate solutions to the problem.

Awaiting a response.

Thanks in advance 


View Complete Post

More Related Resource Links

Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

Multiple groups of roles in membership

Hi,I am developing this website which requires multiple groups of roles inside membership.Here is an example:I want to create a group of states (would be the first group of roles):* Oregon* California* Kansas* Texas* OhioAnd then a second group of profiles:* Admin* Section 1* Section 2* Section 3Then I want to comine these groups, so for example:* Patrick has Oregon and Section 1 role, so he can only access the state of Oregon and Section 1 module on the website.* Laura has Kansas and Section 2 role, so she can only access the state of Kansas and Section 2 module on the website.* John has Ohio, Texas and Admin and Section 1 roles, so he can only....Do you understand what I mean? How can I achieve this with .net memberhip?

Getting an error using FileUpload Control on a server.

Hello FriendsI m getting a problem while executing the following code for my website.This code works perfactly on localhost but when I use d same code on my webpage on the server it does nothing...even it doesnt return any error msg.Plz help me...protected void BtnUpload_Click(object sender, EventArgs e) {        int intFileSizeLimit = 1000;               string strFileNameWithPath = FileUpload1.PostedFile.FileName;               string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);              string strFileName = System.IO.Path.GetFileName(strFileNameWithPath);           int intFileSize = FileUpload1.PostedFile.ContentLength / 1024;                              strExtensionName = strExtensionName.ToLower();        if (strExtensionName.Equals(".doc") || strExtensionName.Equals(".txt") || strExtensionName.Equals(".docx"))        {      

few questions about fileupload control

hey im currently using this to save pictures to a certin folderImgUpload.SaveAs(Server.MapPath("../Img/") + ImgUpload.FileName); my questions is 1. how do i avoid rewriting an image, in other words how do i check if there is another file using the same name? 2. how do i iterate on each image in the folder so that i can print certin html code for each img like for each image print this -> (<img src="Image_Path/Image-name.jpg/gif" width="?" height="?">   tnx

Check membership roles

Hello All, I have the following, for an webapplication I user membership roles. Users are added or removed from a role. I have two things i am wondering how to accomplish.   The first: New or exisiting users have assigned roles for their accounts. This roles can be selected or deselected from a checkbox (when the users is created or edited) . I want to build some routine or function to see if a users is part of a role or if he is assigned a new role. When, in edit mode, a users is part of a role the particular checkbox has to be checked, or if he isn't unchecked. Of course I want to call a function to do that so I don;t have to write the if then statement for all roles, but just one time. I think this should be a public function to call from all pages within the appication, but whatever i try, it doesnt work.  I have written a function in a apart classfile called functions.vb. But the roles syntax isn't recognized. Herby the function{Public Function CheckMembership(ByVal GroupName As Boolean, ByVal User As String, ByVal Group As String) As Integer If GroupName = True Then If Not Roles.IsUserInRole(User, Group) Then Roles.AddUserToRole(User, Group) ElseIf GroupName = False Then If Roles.IsUserInRole(User, Group) Then Roles.RemoveUserFromRole(User, Group)

FileUpload control loses value on postback.

I'm having a little problem with my file uploading. Does anybody know how to maintain the value in the FileUpload control between server posts?I have a form which, among other things, uploads a file. I am using an FileUpload control (created dynamically) to let a user browse their PC for a file and then using the SaveAs method to upload the file to the server.When I'm selecting a file and Click on Next button for processing then selected file is lost.Same is happening with me with HtmlTextArea (dynamically generated) , the problem was that I was not again re-initializing the controls after postback. What I did is re-initialized it in Init method of placeholder (as I have created/placed all dynamic controls in placeholder ).But this thing is not working for fileupload control. I found solution in one of the forum is that "use hiddenField Control to transfer the selected file from the client to server"but this mechanism will only help to retain the name of file in a hidden variable and the FileUpload1.PostedFile.SaveAs(filename) will not work bcz of absense of object (fileupload1).here is code:protected void lnkbtnNext_Click(object sender, EventArgs e) { if (Session["pnl"].ToString() == "0") { /* other stuff code */ } else if (Session["pnl"].ToString() == "1")

How to Set default file name of image in FileUpload Control

helloi want to set  default value in Fileupload control.Because when i select file name using fileupload then save that file to sqlserver database i got problem when no file is select. so i found alternate of that i should store default image into database through fileupload control but now my query is how to set default image to fileupload control.please i want source code.i really need it......tnx in advance

how to customize asp.net membership roles to create separate member area ?


I am using asp.net membership for all the users and roles, right now i have a website on which i have created 2 roles "admin" and "member"

in this website i create accounts, so all the accounts are separated/distinguished by account name

now i was to add one more role "accountholders" and i want to add this role in such a way that an account holder will be able to see his / her account's stuff ...

i as admin will be creating username and password for accountholders and i will provide them their login credentials so that they can login and see what's in their account.

My idea of creating account is that, the accounts that i have in my database will be the key, so when i will create username for particular account , in the create user wizard i should have a drop downmenu will all the accounts name. so the user that i am creating will be linked on that account only ..

how to accoplish this ? please guide me in a right direction...

Lost access to control members and roles


I am working on an application that resides on a development server on our internal network.  The application was originally written to use Membership and Roles.  We got busy almost a year ago before the app was finished, and now we are trying to get it ready to use internally.

The login page works just fine, but I have lost the ability to controls users and roles.  I am running Visual Studio 2010 Professional now on a Windows 7 VM.  I can open the application fine but there is no Web Administration Tool available for me to manage users or roles.  If I go to Website -> in Visual Studio, there is no option for ASP.NET Configuration in the drop down menu.  It simply isn't there.

How can I regain access to manage users and roles for this application?  We are using Forms authentication and the database resides on a  SQL Server 2005 instance on a separate box from the web server and my local VM.

not retaining value of fileupload control in asp wizard control


I am developing a web application in asp.net and c#. I'm using an asp wizard control. there is  6 wizard steps in my wizard. In each phase im using many controls, so that many postback is done during execution.
I am using a asp fileupload control in second wizard step. My problem is that the value selected using fileupload control is not getting when i click wizard finsh button in the final step. values acquired using all other controls are available there.
Hope someone help me.
I just want to get the selected filename in last step. 

profiles, membership and roles


Dear All,

Can someone help me with creating a custom profile, membership and role page something like this:


I'm trying to edit this as my requirment but I can't make it work. I will just need to add detailview to view the entire profile since it's to long for the gridview to handle.

I need to display the gridview custom data then by selecting the select, it will be displayed on the detailview to edit and delete. In create user, need to add my data requirement by making a createwizard page on the left table same as the link. 

FileUpload Control........


Hi..This is Rabbani Shaik..

In project,I got a situation such a whay that...My form contains a fileupload control and 3 dropdownlist controls..The data is binded this dropdowns from the databaase.so, we need complete autopost back right.Now i browse a file and select a item from the dropdown..then what will happen is  the path which i selected earlier is got vanished.Now my requirement is i want to hold the eventhough the page is posted back...Plz give some idea on this..

Thank u....

get full path from fileupload control in client side???


<script type="text/javascript" >

        function SetA()

                    document.form1.action = 'Default.aspx?fileName='+document.getElementById('FileUpload1').value;
    <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server"  />
        <asp:Button ID="btnupload" runat="server" Text="Upload" OnClientClick="SetA()" />



here in the  javascript function i need send full path of upload control?


please help in this situation? if anybody knows other way of sending full path please tell?


thank you,

GridVeiw - EditItemTemlate - FileUpload Control


Hello all

I have a grid veiw binded to an object datasource and one of the fields is the path of an image.

I have in the edit item template a file upload control and a command button to allow the users to upload the image and update the db attribute but i cant figure out how to bind that file upload control to the appropriate database field.

I tryed having a hidden labelbox and an image control and bind that to the object datasource but how can i access the file upload control from c# code to upload the image and update the label or the image controls?

this is my code:

<asp:ObjectDataSource ID="odsProducts" runat="server" 
                                    SelectMethod="GetProducts" TypeName="Project.BLL.Product.Product">
                                <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" 
                                    DataSourceID="odsProducts" CssClass="gvNormal" GridLines="None"
                                    EmptyDataText="No Recods Found" 
                                    AllowSorting="true" AllowPaging="true" PageSize="10">

add dynamically fileupload control


Hi Everyone,

               I have a requirement where i need to add fileupload controls dinamically when Add button is clicked.  In my form i have one Add button and one Save button.

Each time ADD button is clicked one fileupload control must be added to form and i succeded in getting this.

Here is the code

   static int i;
    FileUpload fuPic;
    protected void Page_Load(object sender, EventArgs e)
        if (Session["pnl"] != null)
            Panel pnlfinal = (Panel)Session["pnl"];


protected void btnAdd_Click(object sender, EventArgs e)
        if (i <= 4)
            i = i + 1;

Can I have more control over Roles?


Hi, I was wondering about Roles and what kind of control you can have over it?

I've built a solution with a database and I recently decided to use Roles in my app. But I feel I don't have that much control over it, and that the table with roles (and what ever is included for it to work) sort of plays in the background.

Can I integrate Roles with my existing "user table" or would this seem silly? If I export my database, will the roles setup work on the new server without any further configuration.

I would like Roles to work like a standard Login procedure, where everything checks against the tables I have created myself.
Anyway, would you want to have control over this or can I leave it and trust that the "magic" behind it won't fail at times?

Thanks in advance!

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend