Archive

Archive for the ‘C#’ Category

Unable to find manifest signing certificate in the certificate store

September 11, 2014 Leave a comment

Hi All,

Today after getting latest for my project from Team Foundation Server I was not able to build the solution as the mentioned above error was appearing. After doing some googling finally I found a link which resolved my problem. If this is the case with you then just remove the following from your .csproj file.

<PropertyGroup>

<ManifestCertificateThumbprint>…………</ManifestCertificateThumbprint>

</PropertyGroup>

<PropertyGroup>

<ManifestKeyFile>xxxxxxxx.pfx</ManifestKeyFile>

</PropertyGroup>

<PropertyGroup>

<GenerateManifests>true</GenerateManifests>

</PropertyGroup>

<PropertyGroup>

<SignManifests>false</SignManifests>

</PropertyGroup>

 

After doing so it resolved my issue J.

Reff: stackoverflow.

Regards.

 

Advertisements

Getting a User Or AllUsers from Active Directory using C#

January 2, 2013 1 comment

.NET 3.5 introduced System.DirectoryServices.AccountManagement which manages directory objects independent of System.DirectoryServices namespace. I will be focusing on getting user and AllUsers from AD using AccountManagement dll.

To make is short just attaching code snippet. Details can be acquired from the link which helped me a lot.

After adding the reference in project and namespace in class. We need to have the following functions.

This one gets the domain with the system is connected.

        ///// <summary>
       ///// Gets the base principal context
      ///// </summary>
     ///// <returns>Returns the PrincipalContext object which contains Domain</returns>
       public PrincipalContext GetPrincipalContext()
       {

           PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain);
           return oPrincipalContext;
       }

To get a specific user.

        /// <summary>
        /// Gets a certain user on Active Directory
        /// </summary>
        /// <param name="sUserName">The username to get</param>
        /// <returns>Returns the UserPrincipal Object</returns>
        public UserPrincipal GetUser(string sUserName)
        {
            PrincipalContext oPrincipalContext = GetPrincipalContext();
            UserPrincipal oUserPrincipal =
               UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
            return oUserPrincipal;
        }

To get all users.

        /// <summary>
       /// Getting all users of AD and adding them into List.
       /// </summary>
       /// <returns></returns>
       public List<string> GetAllUsers()
       {
           try
           {
               List<string> users = new List<string>();

               PrincipalContext oPrincipal = GetPrincipalContext();
               GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, "Domain Users");

               if (gPrincipal != null)
               {
                   foreach (Principal p in gPrincipal.GetMembers(false))
                   {
                       users.Add(p.DisplayName);
                   }
               }

               return users;
           }
           catch (Exception ex)
           {

               throw ex;
           }
       }

Hope this helps 🙂 .

Setting Drop Down Selected Index programmatically.

June 9, 2012 4 comments

What is you need to select the item from the drop down list programmatically where you don’t know on which index it would be. For that simplest way is

ddlData.SelectedIndex=ddlData.Items.IndexOf(ddlData.Items.FindByText("value"));
Happy CodingSmile
 

Troubleshooting with Asynchronous post back errors or Error occurred in Ajax control toolkit.

February 7, 2012 4 comments

Its often hard to identify the error occurred in scripts , specially with asynchronous post backs and Ajax update panel.

A good and affective way to identify is described by Mr. Aqeel (An experienced SharePoint developer) to me and i am very glad write it here.

ScriptManager.GetCurrent(this.Page).AsyncPostBackError += new EventHandler<AsyncPostBackErrorEventArgs>(UC_AsyncPostBackError);

I have user control which populates the data and some scripts are being attached to it.

so declared the event  AsyncPostBackError in page load of that user control.

Then into the even of AsyncPostBackError.

void UC_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
      {
          try
          {
              string exc = e.Exception.Message;
          }
          catch (Exception ex)
          {

              throw;
          }
      }

This would let you know the exact exception occurred.

Reset values of all controls in form/ASP.Net page using C#

December 20, 2011 2 comments

Today i am going to blog a post which is not a rocket science , well there is no rocket science ever posted from my side 🙂

I was lying in my blanket , enjoying cozy winter using the laptop , when friend of mine asked ‘what if we need to clear the values of all controls on form to defaults’.

That was not a tough question , more then tough it’s interesting as there are many scenarios in which we need to give default values to the controls on web or form in single click.

foreach is the key loop in that.

So lets start exploring this query.

Initially a form with following controls is designed.

frmMain

  • Check Box : name is chkBox
  • Radio Button : name is rbtn
  • Text Box : name is txtBox
  • Drop Down : name is cmbBox
  • Button : name is btnReset

Now requirement is to set the default values to all the controls on the form or web. Right now i am going with form.

Few controls are being used to make it more easy to understand.
Here comes the code for that on btnReset_Click

private void btnReset_Click(object sender, EventArgs e)

       {

           foreach (Control c in this.Controls)

           {

               switch (c.GetType().ToString())

               {

                   case "System.Windows.Forms.TextBox":

                       ((TextBox)c).Text = string.Empty;

                       break;

                   case "System.Windows.Forms.ComboBox":

                       ((ComboBox)c).SelectedIndex = 1;

                       break;

                   case "System.Windows.Forms.CheckBox":

                       ((CheckBox)c).Checked = false;

                       break;

                   case "System.Windows.Forms.RadioButton":

                       ((RadioButton)c).Checked = false;

                       break;

               }

           }

       }

I have assigned the default values in Switch statement.

frmMain

In case of web page , class representing text box “System.Windows.Forms.TextBox” would have been “System.Web.UI.WebControls.TextBox”

 

Happy coding :).