C#

93K

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

Hi All,

I'm calling the code below.  

  using (Stream stream = request.GetRequestStream()) throws an error the first time but when I call authenticate again from within the catch it works.  

Postman using the same variables works first time.  I've engaged the hosting company but trying to determine if there's an issue on my side or a reason why it would fail the first time from my code.

Thanks in advanced for the help.



  private static Authenticate Authenticate(bool secondTry=false)
        {
            string url = Config.URL + "token";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.KeepAlive = false;
            request.Headers.Add("Authorization", "Basic " + Utility.Base64Encode(string.Format("{0}:{1}", Config.ConsumerKey, Config.SecretKey)));
            
            request.Method = "POST";

            //what I'm sending to the web request on a post.
            string postData = "grant_type=STUFF";
            
            Byte[] data = Encoding.UTF8.GetBytes(postData);
            request.ContentLength = data.Length;
            
                        
            // default settings.
            request.Accept = "application/json";
            request.ContentType = "application/x-www-form-urlencoded";

          
            AttachClientCert(ref request);  // Attaches PFX to request
            setTLS();  //set TLS to 1.2 and other ServiceManager configs.

            try
            {
    

Open in new window

0
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I am trying to run a sql query store it in a sqldatareader and then retrieve those values and want to store into a session to be used by another webform.

picture of error
the datareader says it hasrows but the error says no data is present its kind of a strange behavior.
0
Hi, I Used Crystal Report in C# web application. My database is in access and i set Jet Password there.Can you help me to set Jet Database Password dynamically in Crystal Report.
0
With great difficulty, I'm trying to implement a parser for reading sib codes and analyzing cells tower. I convert a particular ASN.1 EUTRA_RRC_Definitions structure in a C# DLL. In theory I can decode the code and get a file XML structured. I searched everywhere online for examples, but I found nothing.

This is my code that I'm trying to get it works:


public static byte[] StringToByteArray(string hex)
    {
        return Enumerable.Range(0, hex.Length)
                         .Where(x => x % 2 == 0)
                         .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                         .ToArray();
    }

    static void Main(string[] args)
    {

        BCCH_BCH_Message sib = new BCCH_BCH_Message();
        sib.Init();
        const string V = "694c4224198860c1312a984c031807c06e493ab212103108b4890000";
        var buffer = StringToByteArray(V);
        sib.Decode(new Com.Objsys.Asn1.Runtime.Asn1OerDecodeBuffer(buffer));
    }
}

Open in new window



And this is the exception I get: Com.Objsys.Asn1.Runtime.Asn1Exception: 'base class decode method invoked';
I hope someone had already faced with this issue.
0
I'm converting a System.Array to a list.  Reason I'm doing this is because I can't check the values I want with _excelvalues[1,5].
System.Array excelvalues = (System.Array)_excelsheet.get_Range("A" + index.ToString(), 
    "K" + index.ToString()).Cells.Value;

Open in new window

var values = excelvalues.OfType<object>().Select(o => o.ToString()).ToList();

Open in new window

How do I convert BUT migrate everything from the System.Array to the list.  If it is empty the length of the List does not match the System.Array and I want it to always match.

Example:
System.Array[1,12] -> List[12]

Right now I can get System.Array[1,12] -> List[6]
0
I am displaying users and file system rights in a list box using C#. It's a desktop application. My current code looks like this:
private void GetFileUsers(string filename)
{
FileSecurity security = File.GetAccessControl(filename);
AuthorizationRuleCollection acl = security.GetAccessRules(true, true, typeof(System.Security.Prinicpal.NTAccount));

foreach (FileSystemAccessRule ace in acl)
{
	string ruleValue = ace.IdentityReference.Value;
	{
		lstSelectedFilePerms.Items.Add(string.Format("{0} - {1}", ace.IdentityReference.Value, ace.FileSystemRights.Equals(FileSystemRights.FullControl) ? "Read,Write" : 		ace.FileSystemRights.ToString()));
	}
}

}

Open in new window


It shows users in a list looking like this:
ABC\john.smith - Read, Write, Synchronize
ABC\mike.jones - Read, Synchronize

I want to do 2 things. Remove the doman and slash, so it just shows the name. And remove Synchronize. Synchronize displays whenever I assign read or write. But I do not wnat to display it. I've got help in similar questions up here. Hoping for help with this one, too. Thank you.
0
I'm having a Null Reference Exception problem when performing simple calculation using C# and WPF.  My main form has a button that brings up an on screen keypad where a number is entered and then returns the number to the respective text boxes, grossLbsTextBox and tareLbsTextBox.  This code worked fine when I used Winforms, but will not work as WPF.  I'm new to C# so I'm sure it's something simple.  Here is the code.  I indicated the line where the exception is thrown.  Thank you!
 public string strLbsEntered;
        private void btnGrossLbs_Click(object sender, RoutedEventArgs e)
        {
            using (NumberPad formObject = new NumberPad())
            {
                formObject.ShowDialog();
                string strLbsEntered = formObject.StrLbsEntered;
                grossLbsTextBox.Text = strLbsEntered;
            }
        }
        public string strTareLbs;
        private void btnTareLbs_Click(object sender, RoutedEventArgs e)
        {
            using (NumberPad formObject = new NumberPad())
            {
                formObject.ShowDialog();
                string strLbsEntered = formObject.StrLbsEntered;
                tareLbsTextBox.Text = strLbsEntered;
            }
        }
        
        private void grossLbsTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            grossLbsTextBox.TextChanged += onChanged;
            //EXCEPTION THROWN HERE>>> tareLbsTextBox.TextChanged += onChanged;
            

Open in new window

0
Hi,

I am using multiple tab pages and each tab will have many controls.

Except few contols (textbox1 and radiobutton1), remaining controls should get disabled in tab page1.

How to do this in windows c#..?
0
i have a very simple project to show all of the rental cars in one single company location. But the issue is I want to show all of the rental cars like 50 vehicles on the map.
However, the location is the same. How can I show them on the map? If I just use same location, the car icon will basically overlap each other.
i use c#, mvc, and razor.
0
It's about exe whose code is written in C#.
I have some text in form in English and Japanese which i want to be appeared in bold language the problem is in Windows 7 both Japanese and English text are coming properly in bold but in Windows 10 only English text is coming in bold, Japanese text is not coming in bold tried Anti-alias property of text, changed font-name to MS Gothic and  Meiryo for Japanese but nothing worked. Any help would be really appreciated.
0
Cloud Class® Course: CompTIA Cloud+
LVL 12
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

https://developers.google.com/places/web-service/search

I want to use above API to get place = 'rv_park' and my question is if I want to get place type = 'rv_park' in california only.
how can i do that? Basically, I just do not know how to filter by state. I use mvc/c#/razor.

Thank you for your helps in advance.
0
Writing an app that will parse an excel file.  The file has 2 worksheets.  For this purpose say SheetA and SheetB.  I am viewing the process while it is running to see the results.  I want SheetB to displayed in the foreground.  

Any idea how to accomplish?
0
I am trying to extract text from a PDF using iTextsharp library. I've implemented the IRenderListener listener and call PdfReaderContentParse.ProcessContent() to parse:
reader = new PdfReader( in_file );
XMLRenderListener listener = new XMLRenderListener();
PdfReaderContentParser parser = new PdfReaderContentParser( reader );
parser.ProcessContent( page_num, listener );

Open in new window

When the listener's RenderText( TextRenderInfo renderInfo ) method is called, usually the renderInfo.string contains correct text, but not always. For an example, a PDF contains the following symbols:Characters in PDFWhen the method is called, the structure contains the following:
renderInfo content on the symbol 'less than' It is not clear from the picture above, but the PdfString.value actually contains two characters:Invisible characters in renderInfo.PdfString.value
I tried to copy the character from Adobe Reader to the clipboard, and analyzed by Clipboard Viewer.
The "Text" part shows the same bytes:ClipboardViewer Text part, but the Unicode Text Format part shows the correct Unicode value of the character, which is 2266 ClipboardViewer Unicode Text Format part
Also, if I paste that clipboard content to a text editor, I can see the correct character with the code 2266.

The question now: is it possible to make iTextsharp also convert the symbol to correct Unicode value and how to achieve that?
0
Hi All,
Advance thanks for the great solution!
Am using Visual studio 2017 ,c#, MVC. I need to use electronic signature in the .csthml page. I was given strict protocol to follow like not to adapt any third party. i need to capture the signature and display at end of the .cstml page.Please help me or guide me how to do that please...

Kind regards,
Pooja
0
Hi,

I am using Windows C# application which contains many tab.

i want to hide soe of the Tab based on user roles and privileges.

i used below code. but, it is not working..

string title = "Employee DETAILS";
TabPage myTabPage = new TabPage(title);
Tab3.TabPages.Remove(myTabPage);  


When i ran the application, still the "Employee Details" tab are visible...?

what is the problem in the above code.
0
I have this code which I’m using with the attached file and was wondering why the last line (immediately below) is returning a casting error
List<LafAmend> Result = Codes.Where(i => i.Name.Substring(0, 1) == "H");

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApp1
{
    public delegate bool CodeCaller(LafAmend lafamend);

    class Program

    {
        static List<LafAmend> Codes = new List<LafAmend>();

        //static bool MyTest(LafAmend lafAmend)
        //{
        //    int test;
        //    return (lafAmend.Name.Substring(0, 1) == "H" && (int.TryParse(lafAmend.INDG, out test)));

        //}
        static List<LafAmend> Where(List<LafAmend> splodge, CodeCaller del)//variable name not important
        {
            List<LafAmend> output = new List<LafAmend>();
            foreach (LafAmend l in Codes)
            {
                if (del.Invoke(l))
                {
                    output.Add(l);
                }
            }
            return output;
        }
        static void Main(string[] args)
        {
            

            string line2 = "";

            foreach (var line in File.ReadAllLines("/Documents/Courses/CSharpQA/Labs/09  DelegatesAndLambdas/Test/Test.csv"))
            {
                line2 = line.Replace(@"""", "");
                string[] Row = line2.Split(',');
                Codes.Add(new LafAmend
               

Open in new window

0
Is SOLID Outdated?

What are more modern definitions/terms for design principles for OOP?

Thanks
1
I need to sort a foreach statement in an MVC website. I've included the code below. I would like to order the results by item.InteractionDate. I believe it is sorting by the Id rather than the InteractionDate. If you need a snippet from the model, I can add that as well.

<table class="table">
        <tr>
            <th>
                Meeting Date
            </th>
            <th>
                Customer
            </th>
            <th>
                Employee
            </th>
            <th>
                Notes
            </th>
            <th>
                Update Meeting
            </th>
        </tr>

        @foreach (var item in Model.Meetings)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.InteractionDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Customer1.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Employee1.FullName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Notes)
                </td>
                <td>
                    @Html.ActionLink("Edit Meeting", "Edit", "Meetings", new { id = Model.Id}, null)
                </td>
            </tr>
        }
    </table>

Open in new window

0
With C#, how can I check to see if a particular Active Directory group has permissions on a file? So I want to check if DataStewards has read or write access on specific file. If so, enable a button. If not, disable the button. Thanks for any help.
0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Heads-up: Though its little tricky to explain my scenario i will still try my best to explain as clearly as possible.

I have 4 RadGrids(with Column Picker for each RadGrid) on same page & switching between Radgrids doesnt load the current RadGrid name when looking in view source. Though the Data is loaded for different RadGrids.
Issue is with Column Picker.

Requirement: On Change of a RadComboBox List value a different RadGrid has to loaded. Each RadGrid has a COlumn Picker too.
Column Picker -> (list of columns in RadGrid is bided on serverside to a RadListBox and shown in a RadWindow invoked using Javascript )

Basically i have 4 RadGrids(RadGrid1 through RadGrid4) each of which has CommandIteamTemplate -> & asp:LinkButton OnClientClick opens a RadWindow with list of RadGRid Columns whose Display value is True.
Also these 4 RadGrids are 4 seperate user controls with their own unique Javascript methods and Radwindows.

But When ever i chaneg my RAdCombobox value though a different RadGrid is loaded ... Column Picker still shows from the previous RadGrid. At this moment when i look at the view source it still shows previous RadGrid name with java script methods from the same previous RadGrid.

Example: On my Main Page,
Step 1: on page load, RadGrid1 from first user control is loaded with Column picker1 - which was loaded using Javascript1.
sample code in CommandTemplateItem.. <asp:LinkButton ID="lbtnCP" runat="server" …
0
When I compile someone c# code, I got the following warning.  What do I need to resolve this? Any idea?

The primary reference "xxxConfiguration" could not be resolved because it has an indirect dependency on the assembly "xxxAsync, Version=7.05.101.0, Culture=neutral, PublicKeyToken=58aa7495915e0000" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
0
Hi, I.'m trying to set up the zoom of an image ,inside a canvas,  to the value of the ribbon menu item selected.
How can I achieve this?

                 ...
                    <RibbonMenuButton Label="Zoom">
                        <RibbonMenuItem Header="25%"/>
                        <RibbonMenuItem Header="50%"/>
                        <RibbonMenuItem Header="75%"/>
                        <RibbonMenuItem Header="100%"/>
                    </RibbonMenuButton>

...

               <ScrollViewer x:Name="scr_Img" Grid.Column="2">
                    <Canvas x:Name="cnv"  Grid.Column="2" Background="Gray">
                        <Grid Width="{Binding ActualWidth, ElementName=cnv_marking}" Height="{Binding ActualHeight, ElementName=cnv}">
                            <Image x:Name="img_Zoom" 
                                SizeChanged="img_Zoom_SizeChanged"
                                MouseDown="img_Zoom_MouseDown" MouseLeftButtonDown="img_Zoom_MouseLeftButtonDown"
                                Height="{Binding ActualHeight, ElementName=cnv}"/>
                        </Grid>
                    </Canvas>
                  </ScrollViewer>

Open in new window

0
Hi.
I created an folder in project directory (see the attached pic) .
Into this folder I will save some files while user use the program. When program close those file will be removed.
I'm programming in C# WPF.
The problem is that I cannot add files to this folder and get message:
'Could not find a part of the path 'E:\GAB-SW\Program\Source Code\Program_WPF\Program_WPF\bin\Debug\temp\Profile174.png'.'
If I open the project folder my "temp" folder was exist there.
Which path I have to use to save my files in this folder?
Capture1.PNG
Capture.PNG
0
The codes below is extracted from mvc razor view page / c#.
My question is how to pass pair name/value back  to mvc controller.

Thanks,


<script>
        function Validator() {
            return true;
        }
        function UpdateEventCost() {
            if (Validator() == true) {
                var totalCount = document.getElementById("totalcount").value;
                alert("Success");
                var inputs = document.getElementsByTagName("input");
                for(x=0; x<=inputs.length;x++)
                {
                    var id_name = inputs[x].getAttribute("id");
                    var id_value = document.getElementById(id_name).value;
                }
                //window.location.href = "/Home/MotorhomeEdit/15";
            }
            else {
                alert("Error");
            }
        }
</script>

Open in new window

0
I am writing an app that will get a list of directories and files.  I am populating a List<string> to store this information.

I created an ENUM to determine what directories and file extensions should be excluded.  I was trying to figure out how to write linq to "removeall" from the list against the values in the ENUM.  

Want to see if there is a way without looping through each value in List<string>.
public static class Enumerators
{
	public enum ExcludedDirectories
	{
		ABC
	}

	public enum ExcludedFiles
	{
		docx,
		Thumbs
	}
}

Open in new window

My solution is below.
    public static class EnumValidation
    {
        public static List<string> DeleteValues<T>(List<string> value)
        {
            var deletionvalues = Enum.GetValues(typeof(T));

            foreach (var del in deletionvalues)
            {
                value.RemoveAll(x => x.Contains(del.ToString()));
            }

            return value;
        }
    }

Open in new window

Is there a more efficient way?
0

C#

93K

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).