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

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

Creating a One-Dimensional Array for use with AddUsersToRoles Method

Posted By:      Posted Date: October 15, 2010    Points: 0   Category :ASP.Net

Dear All

I've created an Excel spreadsheet for my users to upload into my web application to bulk import  memberships and roles into the application. There are up to 4 different roles which users can be members of so I'm using AddUsersToRoles to add the user to one or more roles in one line of code like this:

r.AddUsersToRoles(usernames, CreateListOfRoles(Role1, Role2, Role3, Role4))

As this line of code expects a one-dimensional array of roles, I have created a function to take in the roles from my spreadsheet, add them into a one-dimensional array, and return that to the AddUsersToRoles method. The CreateListOfRoles function looks like this:

    Function CreateListOfRoles(ByVal Role1 As String, ByVal Role2 As String, ByVal Role3 As String, ByVal Role4 As String) As Array

        Dim ar As New ArrayList

        'If the role boxes are not blank, add them to the array
        If Not String.IsNullOrEmpty(Role1) Then
        End If

        If Not String.IsNullOrEmpty(Role2) Then
        End If

        If Not String.IsNullOrEmpty(Role3) Then
        End If

        If Not String.IsNullOrEmpty(Role4) Then
        End If


View Complete Post

More Related Resource Links

Creating an Array of Rectangles

I am trying to create an Array of Rectangles but can't quite get there as the syntax for the last line eludes me. Is there a way to do this  please?   Public aSquare(10) As Rectangle ---------------------- Dim noOfSquares(9) As Integer Dim strname(9) As String Dim ii As Integer For ii = 0 To 9 Strname(ii) = "mySquare" & noOfSquares(ii) Dim theName As String theName = strname(ii) 'Dim aSquare( ?? ) As New Rectangle Next

How to Pass higher Length of Byte Array to the remoting method

Dear all,I am using a windows application and the businness logic is present in the remote server.Once particular method takes bytearray as input parameter...Whenever the method call is made the function returns value .This is limited for the particular bytearray length. (4109228 bytes).If the length of bytearray crosses 4109228 bytes.I am getting an error that "input stream is not valid binary format".How to Pass higher Length of Byte Array to the remoting method... Greater than 4 MB?I believe something is missing in web.config or app.config...?What could be the issue...? Any sugesstions are welcome....ThanksRavikumar

How to create a multi dimensional array in VB .net

 How do I create a multi dimensional array in visual basic. For example I have a soccer team with players. Each player has an id, first name, last name, address, phone number. How would I represent this using a multi dimensional array?

passing multidementional array as paramater in method

hii want to pass multidementional array as parameter, below the code i worked, is it rightclass ASRateContract    {        public string[,] standardrate = new string[3,2];        public string[,] storagerate = new string[3,3];        public void  setstandardrate( string [3,2]name  )        {            standardrate = name;                   }        public string setstoragerate()        {            return "";        }        public string getstandardrate()        {                 return standardrate;        }

Problem creating method?


I added the extender and when i tried to add the method this message poped up;

Cannot create page method "GetCompletionList" because no Code Behind or codefile was found.

does anyone know why this is happening?

Thanks  =)

Creating dynamic web controls outside Init method



I am creating a dynamic <asp:Table> based on a user's selection from a DropDownList. The number of columns and rows in the table depends on the user's choice from the DropDown.

The final two columns in each row needs to contain an Edit and Delete button. I am able to create these buttons programmatically. However, I am unable to get the click event to fire.

After researching this, it appears to be the case that my dynamic Web controls need to be created in the page Init method.

However, I am unable to do this as I do not know how many table rows, columns and buttons to create, until after the user has made a selection from a DropdownList.

I would be be very grateful for some tips on the correct way to create and enable the events for my dynamic buttons, in this scenario.

Here is a brief outline of how the program currently works (this is just a brief outline I quickly sketched, small details may be wrong!):


<asp:DropDownList ID="ddlMyDropDown" runat="server" 
                onselectedindexchanged="ddlMyDropDown_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>

<asp:Table ID="tblMyTable" runat="server" /> 

Sending JSON Array to an ASP.NET MVC Action Method Argument


 <input type = "submit" onclick = "savePayment()"  value = "Test"/>

    <script type="text/javascript">
        function savePayment() {
            //Creating some test data
            var lineItems = new Object();
            lineItems.Entrys = new Array();
            lineItems.Entrys[0] = new Object({ Name: "Dung", Age: "21"});
            lineItems.Entrys[1] = new Object({ Name: "An", Age: "25" });

            //Posting them to server with ajax
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '<%=Url.Action("TestArray", "Json") %>',
                dataType: 'json',
                data: $.toJSON(lineItems),
                success: function (result) {
                    if (result) {
                    else {

How do you store multi-dimensional array to viewstate?


How do you store multi-dimensional array to viewstate?  I am having a problem.  Here's what I did:

public bool[,,] regsettings = new bool[7,5,4];

bool[,,] regsettings = (bool[,,])ViewState["regsettings"];    // this line works!

regsettings[i,j,tab] = (bool)ViewState["regsettings"]; // this line no working?! The error is: Object reference not set to an instance of an object

the letters i,j,tab are just variables in the loop.  They are there.

I also tried: (bool[,,,]) as a cast and it is a no-go either.?


error when creating a new ribbon tab and using MakeTabAvailable method

Hi there
to add a custom tab in the ribbon. After deploying my solution the tab appears fine and everything seems to be working.

What i did next was , I took the RegistrationId="101" RegistrationType="List" from the XML definisiton and called the MakeTabAvailable method as follows hoping that i can make the tab available in all lists.

protected void Page_Load(object sender, EventArgs e)
            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            if (!ribbon.IsTabAvailable("Ribbon.CustomTabExample"))


however after doing that, the tab appears fine, but it can't load the groups/buttons. The tab just keeps on loading and nothing is rendered. If i click on another tab, and then click on my custom tab i get the following error in the browser.

Webpage error details

how do you get object array number in a method?


Lets say you have four array objects.

test[1] = new test();

test[2] = new test();

test[3] = new test();

test[4] = new test();

then you have your class:

public class test()


   public int i; //initialize some fields

   public int getnumber()


  // what is the array number of the this object? 1, 2, 3, or 4???



so basically, if an object is called: test[1].getnumber   how can this method internally determine what object array number it is currently in?  (without passing an integer from the page)

  it can be either 1, 2,3, or 4.

Best method for creating ages ranges for age when someone was sick



I have a sickness Fact table, with a record for each day each employee was sick. I also have 2 dimension tables, employee and Date.

I want to create ages ranges for the age an employee has on each sick day in the fact table. I solved it by adding an age and age-range column tot the sickness fact table (difference between sickday date and birthdate). After that I created a dimension from this sickness fact table age range columns. But I think the birth date and the age ranges should not be in the fact table, so it works, but in my opinion it is not the way it should be...

So what is the best way to solve this? btw i'm using sql 2008 Standard.

Thanks in advance

Best method for creating a site definition containing a custom list instance



I want to create a new site definition which, when provisioned, includes an instance of a custom list. The custom list definition is contained in a feature as part of the site definition project. What's the best method for creating an instance of this custom list?

I can think of a few ways to do it:

- Modify the onet.xml for my site definition to include an instance of the list

- Use feature stapling to enable my custom list defintion feature when a site is provisioned using my new site definition and include a list instance in the feature.

Is there another more suitable method?



What is the best method/practice for creating a site or functionality within SP 2010 that will allow


As it stands in Visual Studio 2010 I created a new Site Definition and then created 3 new application pages (aspx with cs code behinds; i will call them a/b/c.aspx) and they were added to the 'Layouts' folder in the project.  I also added a data connection Dataset.xsd with all of my stored procedure connections. Looking at my project,  I have 3 aspx pages with cs files in the LAYOUTS folder and one single default.aspx page in the Site Definition 'object'.

If I run the project my browser opens up and navigates to the url "_layouts/[project name]/a.aspx. I can navigate to pages b.aspx and c.aspx and perform my database interactions.  The problem occurs when I then have to deploy the solution/package to the server via a wsp file.  If I deploy the project and then go to create a new site and select my newly created Site definition, SP 2010 will only display the content of the default.aspx page that was located in the site definition 'object' of my project.  All 3 of my custom application pages a/b/c.aspx are no where to be found.

My question is, how to I deploy these 3 application pages?


Any help is greatly appreciated!!!


- gabor

How to hide a method while creating custom control by inheriting WebControl?



I am creating a custom control by inheriting a server control, say LinkButton. There are properties like "BorderColor" available in LinkButton. Let's say, I don't want this particular property to be available when I create an instance of the custom control.

I want to completely hide this particular property (I don't want to override it but disable it.)

My code is as follows:

    Class MyLinkButton
        Inherits LinkButton

        'I want to hide the following method in such a way that if an object of MyLinkButton is created, the following property is not available
        Public Overrides Property BorderColor As System.Drawing.Color
                Return MyBase.BorderColor
            End Get
            Set(ByVal value As System.Drawing.Color)
                MyBase.BorderColor = value
            End Set
        End Property

    End Class

Can anyone help me with this oir provide few pointers?

HELP: Creating an ActionResult method to display a particular database record using Entity Framework


Hi All,

I have an ActionResult method that displays records from a database table (below):

namespace STD.Controllers
    public class StudentController: Controller
        StudentEntities stud;
        public StudentController()
        stud= new StudentEntities ();


        public ActionResult Index()
            ViewData.Model = stud.StudentTable.ToList();
            return View();


I want to design a method "ActionResult Student()" that accepts "Student ID" as a parameter and displays record for that particular student only.

What do I need to do to make this happen? Could anyone please help me with this?

Thanks in advance


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

Creating your SharePoint Governance Plan

One of the most common questions that I get from prospects as I'm talking to them about the creation of a governance plan and process is what does it look like. In other words, there are materials available which describe what should be in a governance plan but there isn't a ton of guidance on what the process of creating a governance plan and process are.
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