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

I have a lengthy stored procedure that is called from my C# program. I have placed a label on the form and want that label to click up one second as long as the stored procedure runs. When it is done, I want to the label to disappear. How do I get this label to behave like a timer? Do I need to use backgrounder worker to accomplish this? Any sample code would be much appreciated.
0
Hi Folks, I'm integrating WPF in PS. though when I add a Progress Bar so it starts from 1 - 100 while trying to add the value to gradually fill the bar, it actually waits for the operation to conclude then display the 100% ... so it skips the animation.... According to the research I've done this weekend, it's behaviour is normal as this progressbar needs to run Synchronized with the WPF load..., does anybody body have any experience on how to fix the issue, or STAmultithreading...?
I know in WinForms a simple definition of the values and a performstep() would fix it

here's the code I'm working on it. Thanks for looking I know this is a very specific task...so I made as simple as possible. Thanks for looking in advance
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')

[xml]$XAML = @'
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="247.857" Width="700">
    <Grid>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FF124F2E" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Label Content="This is just a test" HorizontalAlignment="Left" Margin="265,17,0,0" VerticalAlignment="Top" Foreground="#FF72C196" 

Open in new window

0
Hi All

As mentioned in Internet, LiteDB dll can be used with Dot Net Framework 3.5 but I am facing issue while doing same though the LiteDB dll is working fine with framework 4.0. Can anyone guide on same?

I am trying to use DLL Version 4.1.4.0.

Thanks.
0
I have a table called Customers
which has CustomerID as PK and ParentCustomerID

Now, a single customer can have n number of sub or child customers
Also a sub or child customer can also have n level of customers.

So the customer's tree can go to n level deep.

In C# I can write a recursive method to get all child or sub customer.

But I in SQL I am trying to write a function which can return me sub customerId table till n level.
Do SQL server have recursive support or how can I get this list of customer.
0
I have a utility window that I open in a WFP C# project. One of the options allows a user to transfer a PO. To do that the user needs to enter a PO number. So I pop open another window. On this window I allow them to enter the PO number. I put an Exit button on that window. For some reason I cannot explain, when they click on the Exit button I get "Cannot access a dispose object" message. I am calling this window with the code below. The Exit button code to exit is below that.

Call window with this:

private void btnTransferPO_Click(object sender, EventArgs e)
{
    string TransferText = "Purchase Order";
    using (frmTransferWindow TransferWindowForm = new frmTransferWindow(TransferText))
    {
        if (TransferWindowForm.ShowDialog() == DialogResult.OK)
        {
            TransferWindowForm.Show();
            TransferWindowForm.Activate();
            TransferWindowForm.Focus();
        }
    }
}

Open in new window


Exit button has this code:

private void btnExit_Click(object sender, EventArgs e)
{
    this.Dispose();
    this.Hide();
}

Open in new window


What am I missing here? I have hundreds of other Exit that I close this way with no issues.
1
How could this be done with Linq?
The code loops through all a.b[i].c with index i.

Can i say: Give me a collection of all a.b[i].c for all i (index)?
0
I've code like below;

            if (CreateExcelFile(output_file))
            {
                var workbook = new ClosedXML.Excel.XLWorkbook(output_file);

// Additional to-do will list in here

                GenTplParams(workbook); //This writes something in excel

                workbook.SaveAs(output_file);
            }
        }

Open in new window



GenTplParams() is writing some values on that excel file from 3rd party tool and sometimes it can crash or thrown an error while processing and when i'm getting at the end a blank excel file.

But i'd like to get the file with already written values until the crash/error occurs also it'll give me an advantage to find out which value gives an error. I can easily read the excel file and check the last value and figure out the next value has a problem.

P.S. values are getting from 3rd party softwares COM objects.

Any help makes me glad. Thank you.
0
In my tool i have code like below to conditional formatting the cells as icons

if they are greater than 0 they will get green check icon, if cell value = 0 they will turn to yellow exclamation symbol and if they are below zero they should represent with red cancel icon.

But the problem is it doesnt effect the greaterthen value so my conditional formatting not works properly.

Picture2.png


Any help would be grateful.

Thanks.

        private void ConditionalFormatStatus(IXLWorksheet worksheet)
        {
            IXLCell first_cell = worksheet.Cell(2, 6);
            IXLCell last_cell = worksheet.Cell(worksheet.LastRowUsed().RowNumber(), 6);

            IXLRange range = worksheet.Range(first_cell.Address, last_cell.Address);

            range.AddConditionalFormat().IconSet(XLIconSetStyle.ThreeSymbols, false, true)
                .AddValue(XLCFIconSetOperator.EqualOrGreaterThan, 0, XLCFContentType.Number)
                .AddValue(XLCFIconSetOperator.GreaterThan, 0, XLCFContentType.Number);
            //.AddValue(XLCFIconSetOperator., 3, XLCFContentType.Number);
        }

Open in new window

0
I'm getting input string with format like below probably i need to change with char(10);

no mirror: 0[br]mirror:1

and i would like to write them in one excel cell like;

no mirror: 0
mirror:1

Picture1.png
0
I'm creating a custom drawn form with its own title bar, footer, resizability, all that fun stuff. I've overridden the WndProc method of the form as follows:
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == WM_NCHITTEST)
			{
				Point cursorPosition = new Point(m.LParam.ToInt32());
				cursorPosition = this.PointToClient(cursorPosition);
				Point resizeZone = new Point(this.FooterRectangle.Right - 16, this.FooterRectangle.Bottom - 16);
				System.Diagnostics.Debug.Print($"{resizeZone} - {cursorPosition}");
				if (cursorPosition.Y <= TITLEBAR_HEIGHT)
				{
					m.Result = (IntPtr)2;
					return;
				}
				if (cursorPosition.X >= resizeZone.X && cursorPosition.Y >= resizeZone.Y)
				{
					this.Cursor = Cursors.SizeNWSE;
					m.Result = (IntPtr)17;
					return;
				}
				else
				{
					this.Cursor = Cursors.Arrow;
				}
			}
			base.WndProc(ref m);
		}

Open in new window

This does a great job of allowing me to drag or resize the window but the one thing that's currently missing is being able to display the window context menu on either a right click or when left clicking on the form's icon in the upper left corner. (Screenshot attached for clarity). Can anyone tell me how this might be accomplished?
Window context menu
0
I have a list of usernames/passwords that were the initial passwords given, but should have been changed. I've been told that some of the users used the same password and we want to make sure the password has been changed. We now have a password policy in place for the group, but how can I check if the password has changed? Please note that users did enter a new password, but because a password policy was not in place at the time, some entered the original password as the new password.

I have a file in the following format of username,password:
john.smith,password1
janet.jones,password2
etc.

How can I test the credentials in this file against AD to see what users entered the same password?  I was thinking I would probably use either PowerShell, VBScript, C# or VB.net.
0
I am working on a C# utility program and one of the utilities that gets called will take about 30 minutes to complete. The routine is a stored procedure that runs completely in SQL.  What is the proper way to display a timer so the user will know that work is in progress?
0
I have an ASP.NET Web Site built in .NET 4.7 using C#. In my web.config, I have the following Forms authentication (see web.config below) with the "domain" attribute set to ".mydomain.com" for my Production environment. Is there a way to dynamically change its value (via C#)  based on the environment, such as QA, Staging, etc. For example, if (Request.Url.AbsoluteUri.StartsWith("http://qa")), then I want to change the value of the "domain" attribute to ".myqadomain.com", and  if (Request.Url.AbsoluteUri.StartsWith("http://staging")), change the value to ".mystagingdomaincom".

Here's the <authentication> section of my web.config:
    <authentication mode="Forms">
      <forms path="/" name="MyWebSite_Auth" loginUrl="~/login.aspx" defaultUrl="~/customers/Default.aspx" protection="All" slidingExpiration="true" domain=".mydomain.com" timeout="350" cookieless="UseCookies"/>
    </authentication>

Please provide the necessary C# code to accomplish this.

Many thanks in advance.
0
When I say Clear Controls Recursively I mean resting text to empty strings and removing UserControl from flowLayoutPannel

The Picture bellow the blue is a panel inside this I have TextBoxes, Labels, tabControl & groupboxes
Inside the groupboxes there are TextBoxes, Labels, and RichTextBox These need resetting back to Empty strings

the tabControl has FlowLayoutPanel with UserControl

This Code finds child controls but doesn't find the grandchildren

I'm aware  I should probably use a switch rather than if / else if but I can't call it recursively I get error  

The name 'ClearMoviePanel' does not exist in the current context

Open in new window


CODE

//  To Call
        ClrearMoviePanel(MoviePanel.Controls);

        public void ClrearMoviePanel(Control.ControlCollection controls)
        {
            foreach (Control control in controls)
            {
                foreach (Control child in control.Controls)
                {


                    if (child.Name == TitleTxtBox.Name)
                    {
                        continue;
                    }
                    else if (child is TextBox || child is Label || child is RichTextBox)
                    {
                        child.Text = string.Empty;
                    }
                    else if (child is FlowLayoutPanel)
                    {
                        child.Controls.Clear();
                    }
                    else if(child.HasChildren)
                    {
  

Open in new window

0
Hi,

I want to build a WPF .Net Core application an I want to include the .dot net framework so “everything” is self contained. So I can run side by side and not have to distribute he framework as a seperate package. Sorry can remember the feature name.

My question is how to do that an enable it with Visual Studio 2019.

Also will this work with a Windows 7 target as well?

Thanks
ward
0
I have an old MVC project that I want to upgrade/port to ASP.Net Core Web Applications. I've been reading some articles:

Ex: https://arghya.xyz/articles/porting-aspnet-apps-to-aspnet-core-2.0/

I created an ASP.Net Web Application Core. I run it and I get the first page. I click on Login and takes me to the login page. But, I don't see the login page in the project.
I did a search and I don't see it. I clicked on "show all files" but still don't see it.

See screenshots below:

e1.png
e2.png
0
I have a legacy program which keeps Lists as in if X, Y are classes then we have variables
var listx = new List<X>();
var listy = new List<Y>();

Open in new window

My question is should I create class LISTX and LISTY so this becomes
var listx = new LISTX();
var listy = new LISTY();

Open in new window

or is that just a waste because the class would essentially be empty, just another name for List<X> and List<Y>?

class LISTX : List<X>
{
}

Open in new window


Or maybe it's a good way to go if I can eventually migrate some code into those classes? (And maybe eventually rename the class when it becomes more obvious what it represents.)

(I initially tried creating those classes yesterday, then decided it was a silly idea and removed them. Now I'm not so sure.)
0
I am creating a hyperlink from my codebehind of asp.net. when i click on the link i want the other form to be opened as a pop up. how can i do that

this is how i create my hyperlink

var navigation = new TableCell();
navigation.Controls.Add(new HyperLink { Text = "Edit", NavigateUrl = "newpage.aspx?Account=" + dt.Rows[i].ItemArray[0] + "&ID=" + dt.Rows[i].ItemArray[1] + "&Period=" + dt.Rows[i].ItemArray[12] });
0
This can't be that hard but I can't come up with a solution...

1. I have a datatable

Amount  LocId
------------  -------
1.00           STL
2.00           Laundry
4.00           STL
5.50           XYZ
9.00           STL
1.50           Laundry

2. This is what I want to do -->Add up the rows per "LocId" and insert into a table. So:

14.00      STL
3.5           Laundry
5.50         XYZ

3. I thought about looping and comparing LocId from one row to the next one. If same, add up. If not, move to the next row but then I think I have to do this for second row, third one, etc. Maybe somehow with LINQ?

Again, this can't be that hard.
0
In my application i have several functions to organize my tool they are mostly using for scripting. To organize them in proper way i'm creating classes to store them(using like VB.net's module), but when i'm look back to my application there are several methods which are defined "public static".

Is there anyway to use them correctly or what's your approaches for that. I want to organize them and call them from another classes.

Any help would be grateful.
0
Hello Experts

I am trying Use wildcards (or other method) to Unzip a file in C# where the file name can be found based on first part of text only. So far am unable to accomplish this.

For example I have the following code:

string targetDirectory = @"C:\TestDirectory";
                    string zipFile = @"C:\TestDirectory\Test_09/20/2019.ZIP";
                    ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    fz.ExtractZip(zipFile, targetDirectory, "");


This code works fine to unzip files as long as the exact zipped file name is listed...

I want to be able to use wild cards or other method to unzip a file called Test_09/20/2019.ZIP without the program having to know about the _09/20/2019 part of the file.

In other words I would like to unzip a Test_"Any date or other text".ZIP file by only knowing about Test.ZIP a the file name.

I tried Test*.ZIP in the above code but the * was an unrecognized character.

Does anyone know how to do this?

Thanks!
0
I'm planning to create a small gui which has several module gui's and when i'm clicked it i'd like to show it. But don't know what's the correct approach to do that.

Any help would be grateful. I added a small sketch to show.OpenWindow.png
0
I have a global variable named "Globals.ServerPre" with com class type "SpckCOMApp". When i'm trying to release object i have some issues.

  public static  void KillServerPre()
        {
            if (Globals.IsServerPreRunning)
            {
                try
                {
                    ReleaseComApp(Globals.ServerPre);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Pre instance couldn't killed!");
                }
                return;
            }

      }

Open in new window




In below code i've issue;
com = null;

Open in new window

doesn't work/ doesn't assigns the null value to variable and Globals.ServerPre continue to show as not null.

But if i changed it to Globals.ServerPre=null; it assigns the null value to variable.

  public static  void ReleaseComApp(object com)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(com);
                com = null;
                // Globals.ServerPre = null;
                Log.Information("Pre(Solver) instance successfully killed!");

            }
            catch (Exception ex)
            {
                Log.Error(ex, "Object: " + com.ToString() + " couldn't released!");
            }
            finally
            {
                GC.Collect();
            }

            return;

        }
0
In c#, how to read all child, not one by one?

string xmlString = "<people><firstname>John</firstname><lastname>John</lastname></people>";            

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlString);
            foreach (XmlNode node in xmlDoc.SelectNodes("//people"))
            {
                //how to loop and read all child?
            }

Open in new window

0
What I ultimately want is dynamically create controls depending upon the number I get from db.

 for (int intControlIndex = 0; intControlIndex < number returned from db; intControlIndex++)
{
add a label and hyperlink
add a panel
add few check boxes inside the panel
}

so if number returned from db = 2 I need the output something like this

I need the above items to be shown in same sequence that I have shown above.
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).