C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

Share tech news, updates, or what's on your mind.

Sign up to Post

ADCycleGroups is a multilevel GPO phase-in tool I developed to automate the moving of computers and users from one GPO version to the next, until it finally gets to the latest GPO policy. This allows me to gradually move computers and users from one version of a policy to the next.
3
LVL 56

Author Comment

by:Shaun Vermaak
Yes
0
LVL 29

Expert Comment

by:Andrew Leniart
Great work Shaun - very useful.

Endorsed!

Regards, Andrew
0
Python 3 Fundamentals
LVL 19
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

This is a simple web application that allows you to use Active Directory photos anywhere that you can use a HTML tag
3
I have personally never liked the standard Windows Service template that comes with Visual Studio. This article describes how I created a Visual Studio template build on the Topshelf library that I use to develop stable Windows Services.
1
Over time I have seen a number of questions asking how to logoff users at a specific time. I personally haven't required this but decided to develop a little Windows service that manages this via schedule and not a legacy scheduled task running shutdown /l or via AD logon hours
1
LVL 67

Expert Comment

by:McKnife
Will I understand the limitation once I use yours? I have no idea, what you mean. I want to logoff all users at a given time - I can and I don't need extra tools or schedulers.
0
LVL 56

Author Comment

by:Shaun Vermaak
Many ways to skin a cat. I prefer to use methods where I can replace a config file an alter all configuration.
0
Group membership expiration is a superb new feature included with Active Directory 2016 functional level. But what if you want this functionality but you haven't upgraded yet? Since I have many clients that cannot yet leverage this new feature, I have developed a custom tool.
2
LVL 67

Expert Comment

by:McKnife
That's too bad. I had hoped that it would, so that we could switch to your tool instead of using what is built-in @2016 server, because the built-in method has a funny limitation (at least in our domain) : it won't work with times of 5 minutes or less (6 minutes is ok!). When using 5 minutes or less, the group will get populated, but the kerberos ticket will not be granted for whatever reason.

We would like to use less than 6 minutes, sometimes, for example when we activate a software license, we give the machine internet access for the shortest time possible (working close to the military, here, no direct internet access allowed). And to do so, we use AD groups, that the SQUID proxy works with. We would like to use, say, 1 minute, but we can't do less than 6... :-)
0
LVL 56

Author Comment

by:Shaun Vermaak
Will look into it. Our requirement usually for a ~day but yours make sense
0
Working with Arduino
In this article, I will tell you how to read data and control a USB connected Arduino from .Net and UWP applications.
0
Google Elevation API
The article's main focus is , to create a C# console application using Google's Elevation API. For more detailed information about this topic, use the attached links.
0
GEOCODING / REVERSE GEOCODING
The article's main focus is , to create the application using Google's GeoCoding/Reverse Geocoding. This article will teach you what GeoCoding and Reverse Geocoding is and how to write a simple C# console application. I also added some links, for more detailed information for this topic.
1
How many times have you tried using Office InterOp to manage various custom properties? If you have ever tried it then you will see the article image very appropriate. After spending hours trying to solve a question I finally gave up on Office InterOp and took an easier way out - OpenXML SDK.
0
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would attempt to address those here.
0
Exploring SQL Server 2016: Fundamentals
LVL 19
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
7
LVL 25

Expert Comment

by:Alan
Thumbs up working now - thanks!

Alan.
1
LVL 13

Expert Comment

by:Senior IT System Engineer
thanks for sharing.
0
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
0
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
6
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
5
Code Performance
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
3
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a few months or a few weeks to get market trend inform.
0
DelegatesInC#
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that understanding with Experts-Exchange users.
2
LVL 11

Author Comment

by:ROMA CHAUHAN
Hi St. Jimbo,

Thanks for your valuable inputs.

As this is my very first article so I was not aware of all these points. I have submitted my article with the specified modifications.  Please review it again.


Thanks,
Roma
0
LVL 76
Any method which matches the above delegate type can be assigned to this MyTestDelegate delegate.
What do you mean by "matches"?

To call those methods through delegate, we have to use Invloke() method of that delegate.
You can also just invoke the delegate like a function using parentheses, which if memory serves is just syntactic sugar for Invoke:

objMyTestDel(9);
 
objMyTestDel(15);

Asynchronous execution of method through delegate
Don't forget about the async/await functionality of .NET!
0
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
3
LVL 68

Expert Comment

by:Jim Horn
Very well written, and I can see how this can be very useful.  Voted Yes.
0
LVL 111

Expert Comment

by:Ray Paseur
0
Entity Framework 6
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
2

Expert Comment

by:Budheshwar Tiwari
HI Alexandre,

i have use the second tricks of you mention this article but the error is bind the

==>  Invalid attempt to read when no data is present.
can you please help this issue.
**********The Store Procedure result is ******

SQL query Window**********These are Model ************

  public class UserDashboard
    {
        public List<UserMenuItem> DealOfTheDay { get; set; }
        public List<UserMenuItem> UserMenuList { get; set; }
        public List<MenuItemImage> MenuImageGallery { get; set; }
        public int TotalCartCount { get; set; }
    }
    public class UserMenuItem
    {
        public long ItemId { get; set; }
        public string ItemCode { get; set; }
        public string ItemName { get; set; }
        public decimal OutletPrice { get; set; }
        public decimal Calorie { get; set; }
        public string Discription { get; set; }
        public string UnitName { get; set; }
        public string ImageTitle { get; set; }
        public bool isFavorite { get; set; }
    }
    public class MenuItemImage
    {
        public int ImageID { get; set; }
        public long ItemId { get; set; }
        public string ImageTitle { get; set; }
    }
 ************* This is the function of code first multiple select Statement*************
        public UserDashboard GetAllUserDashboardData(long UserId, byte WalletType = 1)
        {
            UserDashboard result = new UserDashboard();
            var command = _Context.Database.Connection.CreateCommand();
            command.CommandText = "[dbo].[APIUserDashBoardData]";
            command.CommandType = CommandType.StoredProcedure;
            var userid = new SqlParameter("@UserId", UserId);
            var to = new SqlParameter("@WalletType", WalletType);
            command.Parameters.Add(userid);
            command.Parameters.Add(to);
            try
            {
                _Context.Database.Connection.Open();
                // Run the sproc  
                var reader = command.ExecuteReader();
                #region First Method to bind the entity by ef
                //// Read Blogs from the first result set
                //var DealOfTheDayList = ((IObjectContextAdapter)_Context)
                //    .ObjectContext
                //    .Translate<UserMenuItem>(reader, "Result1", MergeOption.AppendOnly);


                //foreach (var item in DealOfTheDayList)
                //{
                //    result.DealOfTheDay.Add(
                //        new UserMenuItem()
                //        {
                //            ItemId = item.ItemId,
                //            ItemCode = item.ItemCode,
                //            ItemName = item.ItemName,
                //            OutletPrice = item.OutletPrice,
                //            Calorie = item.Calorie,
                //            Discription = item.Discription,
                //            UnitName = item.UnitName,
                //            ImageTitle = item.ImageTitle,
                //            isFavorite = item.isFavorite,
                //        });
                //}
                //// Move to second result set and read Posts
                //reader.NextResult();
                //var MenuImageGalleryList = ((IObjectContextAdapter)_Context)
                //    .ObjectContext
                //    .Translate<MenuItemImage>(reader, "Result2", MergeOption.AppendOnly);


                //foreach (var item in MenuImageGalleryList)
                //{
                //    result.MenuImageGallery.Add(
                //        new MenuItemImage()
                //        {
                //            ImageID = item.ImageID,
                //            ImageTitle = item.ImageTitle,
                //            ItemId = item.ItemId,

                //        });
                //}

                //// Move to third result set and read Posts
                //reader.NextResult();
                //var UserMenuList = ((IObjectContextAdapter)_Context)
                //    .ObjectContext
                //    .Translate<UserMenuItem>(reader, "Result3", MergeOption.AppendOnly);


                //foreach (var item in UserMenuList)
                //{
                //    result.UserMenuList.Add(
                //        new UserMenuItem()
                //        {
                //            ItemId = item.ItemId,
                //            ItemCode = item.ItemCode,
                //            ItemName = item.ItemName,
                //            OutletPrice = item.OutletPrice,
                //            Calorie = item.Calorie,
                //            Discription = item.Discription,
                //            UnitName = item.UnitName,
                //            ImageTitle = item.ImageTitle,
                //            isFavorite = item.isFavorite,
                //        });
                //}

                #endregion
                #region Second Method to bind the entity by ef
                // Read Blogs from the first result set
                while (reader.Read())
                    {
                        result.DealOfTheDay.Add(
                            new UserMenuItem()
                            {
                                ItemId = reader.GetInt64(0),
                                ItemCode = reader.GetString(1),
                                ItemName = reader.GetString(2),
                                OutletPrice = reader.GetDecimal(3),
                                Calorie = reader.GetDecimal(4),
                                Discription = reader.GetString(5),
                                UnitName = reader.GetString(6),
                                ImageTitle = reader.GetString(7),
                                isFavorite = reader.GetBoolean(8),
                            });
                    }
                    //// Move to Second result set and read Posts
                    reader.NextResult();
                    while (reader.Read())
                    {
                        result.MenuImageGallery.Add(
                            new MenuItemImage()
                            {
                                ImageID = reader.GetInt32(0),
                                ItemId = reader.GetInt64(1),
                                ImageTitle = reader.GetString(2)
                            });
                    }
                    //// Move to third result set and read Posts
                    reader.NextResult();
                    while (reader.Read())
                    {
                        result.UserMenuList.Add(
                            new UserMenuItem()
                            {
                                ItemId = reader.GetInt64(0),
                                ItemCode = reader.GetString(1),
                                ItemName = reader.GetString(2),
                                OutletPrice = reader.GetDecimal(3),
                                Calorie = reader.GetDecimal(4),
                                Discription = reader.GetString(5),
                                UnitName = reader.GetString(6),
                                ImageTitle = reader.GetString(7),
                                isFavorite = reader.GetBoolean(8),
                            });
                    }
                    reader.NextResult();
                    while (reader.Read())
                    {
                        result.TotalCartCount = reader.GetInt32(0);
                    }
                    #endregion
               
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                _Context.Database.Connection.Close();
            }
            return result;
        }

*********For more detail see the file attachments********************
Thanks
VS2017.png
0
HTML5 and CSS3 Fundamentals
LVL 19
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Exception Handling is in the core of any application that is able to dignify its name.
In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
2
Project templates provide the class structure and definition of service contracts, data contracts and other important features in 
Visual Studio for Windows Communication Foundation
. Using these predefined template helps you to write a service with minimal code interaction and it will lead you to build more advanced services for your projects.

There are four different types of templates present in Visual Studio. The first two are the most commonly used to build, test and deploy SOA architectural applications.
 
1. WCF Service Library:
The WCF Service Library project (C#) consists of three files; IService1.cs, Service1.cs and App.config. The WCF Service Library project (VB.Net) is consists of three files; IService1.vb, Service1.vb and App.config.

This type of project is suitable when we are focused on building the services first and deployment later.
  • IService File: This is the interface where the WCF service attributes are applied. In this file you place the definitions of data contract methods/operations.
  • Service File: This file is inherited from IService interface file and includes the implementations of defined interface's data contract methods/operations. 
  • Application Configuration File: In this file, you place the definitions of secure HTTP binding, endpoints of services and other important features.

2. WCF Service Application:
The WCF…
0
You can find plenty of algorithms on the Internet that provide the Encryption - Decryption functionality. One of them is the AES algorithm. AES stands for "Advanced Encryption Standard".

The Advanced Encryption Standard was established by US National Institute of Standards and Technology in 2001. It was based; on the work of two Belgian cryptographers, Joan Daemen and Vincent Rijmen, who submitted the proposal to NIST during the selection process.

In the AES algorithm, there is a terminology we use called 'Cipher Mode'. There are different types Cipher Modes present in the algorithm. Based on your specific needs and requirements you can select the Cipher Modes. Let's have a look at what these are and how they differentiate from other cipher modes.

1. Electronic Code Book Mode: This mode doesn't require any feedback to be applied. You pass the plain text/data using this and and get the resulted Cipher data from it directly. The main disadvantage is that this mode will return the same cipher data on passing the same type of plain text in loop; if you pass 'Hello, World!' three times in this mode then it will return same cipher data in each iteration. That is why this mode is considered as 'Vulnerable' and not recommended for use.

2. Cipher Block Chaining Mode: This mode is required to add the feeback to modify the pre-encrypted data; with the feedback it will make each cipher data…
1
Mulithreading is a wonderful concept but it is one of the most complex way to achieve a task. Microsoft had provided probably the most efficient way to handle this problem by using async calls and thread pool. This provides an easy way to handle more than one task in an efficient way. But the biggest problem is thread creation and disposal of thread in this programming scenario. A common problem we are facing with UI programming is we are executing a task which takes a long time.

And if we are trying to do the same in Main Thread of application it freezes the UI until the completion of job. For example in the given program we are trying to run infinite loop and trying the display the count on textbox

 
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private TextBox textBox1;
        private Button btnStart;
    
        public Form1()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.btnStart = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // btnStart
            // 
            this.btnStart.Location = new System.Drawing.Point(134, 27);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(75, 23);
            this.btnStart.TabIndex = 0;
       

Open in new window

0
Hi,

There are a lot of written methos of getting the difference between two dates, but I couldn't find the one I needed. I need to have a real difference like 3.75 months between the two dates.

Not every month has the same amount of days and the February is also an issue here. So I made myself a method doing this:

/// <summary>
/// Get months difference between two dates
/// </summary>
/// <param name="from">from date</param>
/// <param name="to">to date</param>
/// <returns>months (double) between </returns>
internal static double GetMonths(DateTime from, DateTime to)
{
	/// |-------X----|---------------|---------------|--X-----------|
	///         ^                                       ^
	///       from                                     to

	//change the dates if to is before from
	if (to.Ticks < from.Ticks)
	{
		DateTime temp = from;
		from = to;
		to = temp;
	}

	/// Gets the day percentage of the months = 0...1
	///
	/// 0            1                               0              1
	/// |-------X----|---------------|---------------|--X-----------|
	/// ^^^^^^^^^                                    ^^^^
	/// percFrom                                    percTo
	double percFrom = (double)from.Day / DateTime.DaysInMonth(from.Year, from.Month);
	double percTo = (double)to.Day / DateTime.DaysInMonth(to.Year, to.Month);

	/// get the amount of months between the two dates based on day one
	/// 
	/// |-------X----|---------------|---------------|--X-----------|
	

Open in new window

3
LVL 3

Author Comment

by:TGB01
Hi mahmuod,

I know, but using this you get the real difference between two dates, like the days between the two dates (Double). In the TimeSpan, there is no Month property.

And in my case, the method is using one month as 100%, so every month can have different amount of days. So the same amount of days between two dates can have multiple results depending on the choosen dates.
0
LVL 1

Expert Comment

by:SimonPrice3376
because of the complexity of the question, have you mapped out the sum on paper?  

if you can get the sum right using proper math, you should then be able to recreate the sum in a method \ function and return the value accordingly.
0
Sometimes when developing windows forms application, it becomes an important part of application design to persist the state of windows form after it is closed.

One such example that comes to my mind is an application called “Sticky Notes”.

Here the user is expected to open a notepad which she can re-size as and when required, can write few notes on it and then close this form. The notes are to be saved in a persistent storage like Database or XML.

Next time when the user opens that sticky note, it should open in the same size and display the notes that were written by the user last time.

As far as persistence of the notes to Database and/or XML file is concerned, I know there are many ways to do it. This article however deals with the second part of the problem, i.e. persistence of the form state in the application.

Some people might argue that if we can save note’s data in DB/XML we can also save form’s State. But, i personally feel that since form’s state is the data related to user interface, so it should be persisted somewhere in the application.

So let’s begin this tutorial by understanding the problem statement first:-

The Problem Statement

During the flow of an application, a windows form is opened. The User the re-sizes the form, make some other activity with the form and closes the form. Next time when the user opens this same form again, the size of the form should be same as when the form was closed.

Solution

Looking at …
4
LVL 8

Expert Comment

by:TheMozz
Great article! I especially appreciate the comment about separating the application data from the UI specific data. It is easy to forget the difference when working on an app that has to be done "Right Now" (not that things are ever done that way..).
0
LVL 16

Expert Comment

by:Easwaran Paramasivam
Excellent Article!!
0

C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).