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 am trying to get a object out of IEnumerable collection which is in Dictionary.

I have a method which return IEnumerable of Employees. so In my code I am saying:

var emplist = employeelist.GetEmployeelist(ids);

Open in new window


I want a get a object depeding on the key i.e empid. So I am saying:

if(emplist.containKey(id)) { var emp = emplist.where(x => x.key == id);

Open in new window


so I am hoping that i would get the employee object in emp and can go though the emp object like emp.id, emp.name etc.

Could you please let me know how can i get the object from IEnumerable collection which is in Dictionary?
0
This code in Java works perfectly:

    URL url = new URL(PREREQ_URL);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("Authorization", authorization);
    System.out.println(authorization);

    InputStream is = (InputStream) con.getInputStream();
    BufferedReader in
            = new BufferedReader(new InputStreamReader(is));

    String line;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    in.close();

Open in new window


I am trying to convert it into C# and I am getting
System.Net.WebException: 'The underlying connection was closed: An unexpected error occurred on a send.'

This is what I have:

    Uri prereqUri = new Uri(PREREQ_URL);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(prereqUri);
    //request.Headers["Authorization"] = authorization;
    request.Headers.Add("Authorization", authorization);
    //request.PreAuthenticate = true;
    request.Method = "POST";
    //var postData = "Authorization=" + authorization;
    //var data = Encoding.ASCII.GetBytes(postData);
    //request.ContentLength = data.Length;

    //using (var stream = request.GetRequestStream())
    //{
    //   stream.Write(data, 0, data.Length);
    //}

    var response = (HttpWebResponse)request.GetResponse();

Open in new window


I have also tried the commented out code with the same problem. Any ideas, please.
0
Hello,

I have always been a c#, .NET developer and our company is gradually transitioning to MVC and Angualr.  I am very new to MVC and Angular concepts, done a few courses about Angular and MVC on plural sight since last week and that is where I am at currently.

One the tasks I have on hand is to display a modal pop from from which needs to triggered to display from an MVC controller based on certain conditions and this modal pop up form which is a very basic form needs to be displayed using Angular.

This Modal pop up is as simple as it gets and will have a text box which needs to have an input of a 14 digit alpha numeric characters ( failure on providing it will show a validation error message on the modal pop up itself) a submit and a cancel button. On click of the submit button (after validation), the MVC controller needs to receive this value and continue its normal process.

Currently the MVC page where the modal pop up needs to be displayed has a few controls and a button. On click of this button the MVC controller calls the data access method and stores certain values in the DB. But if this 14 digit code is missing it currently throws an exception. Hence the need to for a modal popup for the user to enter the missing data.

I would very much appreciate if you can point me in the right direction by providing me some useful links or some code samples.

Thanks in advance AJ
0
dateshit.JPG

everything looks right why is it still throwing that stupid error, i hate strings and date they need to do something regarding this :(
0
I have an MVC 5 project where I have local processing RDLC reports using report viewer 14. For some reason I have a report that is called and after about 1 minute and 40 seconds and my site says that "No data was heard from..." in Chrome, and in IE it thinks there is a DNS problem after that 1 minute and 40 seconds. I have confirmed the SQL Query running in just a second. I am thinking that the biggest time factor is I am using a Matrix in my report.

I guess I would like to know how to extend my timeout. I have had other stored procedures that take a long time to run and I used the below reference and it fixed that. But I do not know how to fix this problem.

https://www.codeproject.com/Questions/238245/Dataset-xsd-Timeout-Problem
0
I've written a C# asp.net application that uses Microsoft.Office.Interop.Excel.  Application creates an Excel spreadsheet, saves it and then tries to close and quite Excel but the Excel process is still running in the Task Manager.  (same code works in a console app or Windows Forms application but not in my asp.net web app).

Here is the basis of the code:

using MyExcel = Microsoft.Office.Interop.Excel;
.
.
.
MyExcel.Application xlApp;
MyExcel.Workbook xlWorkBook;
MyExcel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
.
.
 xlApp = new MyExcel.Application();
 xlWorkBook = xlApp.Workbooks.Add(misValue);
 xlApp.DisplayAlerts = false;
 xlWorkSheet = (MyExcel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
 xlWorkSheet.Name = "Daily Report";
.
.
xlWorkBook.SaveAs(myFile, MyExcel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, MyExcel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close();
xlApp.Quit();

Open in new window

0
Hello, and thank you for your assistance!

I would like a graphical design interface to edit and dress up some web pages that I will create using Microsoft C# MVC Code First migrations, which create CSHTML files with Razor code within them.  Is there a tool that will let me drag & drop, etc., move things around visually and let the tool change the file as I design it?  And if there are several, which one or ones are the easiest to learn & use?  I am also in a time crunch with this project.  

Many thanks!

Dean
0
Hello Experts,

I am fairly new to C# programming for MS Word document.
I am trying to create an interactive Word document for users.
I have separate csv file that has values for "Country Name, Country code".
Now from my word document, I want users to have ability to search by country name and pick the value of country code to the text box in Word.
Not sure if have to use any local database like SQLLite or how I can make this search interactive for users from the Word document.
Can you help by throwing pointers that I can use to get started.

Thank you.
0
or an OPENXML spreadsheet, can you create all the rows needed like this loop

for (uint i = 1; i < 44; i++)
 {
 row = new Row() { RowIndex = i };
sd2.AppendChild(row);
}

Open in new window


And elsewhere in the code reference specific rows and create new cells etc as needed
row1.RowIndex = 5;

//create a new cell
Cell celltest = new Cell() { CellReference = "I5", DataType = CellValues.String, CellValue = new CellValue("Issue:"), StyleIndex = 7 };
                

//append the cell to the row
row1.Append(celltest);

Open in new window


And then update cells later by referencing the specific row index?
Do the cells need to be created/updated during the creation of each row?

I am not having much luck with this approach and want to ensure I am not going crazy.

Thanks
Jed -
0
I have an c# application created in VS2005(.Net Framework 2.0) using Microsoft Interop Word Dlls.
Now we are migrating this application to Windows 10 and while building the solution I get the below errorsScreen shot of Word Interop ErrorScreen shot of Word Interop ErrorScreen shot of Word Interop ErrorScreen shot of Word Interop Error
0
I am trying to get a Salesforce report into a C#.net application so I can save as a datatable,  then saving as a CSV file, i am able to connect and get what seems to be the report data but cant figure out how to use the data.

Can someone point me in the right direction on how to use the data from the report - thanks

Code I am using

        static void Main(string[] args)
        {

            System.Net.ServicePointManager.Expect100Continue = true;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var task = ExecuteReport();
            task.Wait();

            Console.ReadLine();
        }

        public static async Task<string> ExecuteReport()
        {
            var sf_client = new Salesforce.Common.AuthenticationClient();
            sf_client.ApiVersion = "v39.0";
            await sf_client.UsernamePasswordAsync(consumerKey, consumerSecret, username, password + usertoken, url);

            string reportUrl = "/services/data/" + sf_client.ApiVersion + "/analytics/reports/" + reportId;

            var client = new RestSharp.RestClient(sf_client.InstanceUrl);
            var request = new RestSharp.RestRequest(reportUrl, RestSharp.Method.GET);
            request.AddHeader("Authorization", "Bearer " + sf_client.AccessToken);
            var restResponse = client.Execute(request);
            var reportData = restResponse.Content;

             return reportData;
        }

Open in new window

0
I had this question after viewing Textbox Textchanged event doesn't fire....
0
Hi,

I have a number of problems with using C# Tasks.

I have put all my questions in code but have copied them in here.

Given I have a number of questions I am hoping to get as many answered as I can. As I suspect the same problem might be causing the others.

Ideally I would like to get some edits to the code below to fix the problems.

If I need to I will adapt the code and post some extra questions with what is left to offer some more points in other questions.

Thanks,

Ward.


 Description:

 Here is some code that will simulate processing items in a queue. I want it to process from 1 - n and do it asynchronously and display
 a progress bar and for the UI to be responsive. Ultimately it will be reading file btw. I can work that bit out. Just getting the UI part
 first.

 For example if I put in 3 items.

 1 - Count from 1 to 100.
 2 - Count from 1 to 100.
 3 - Count from 1 to 100.

 So an interim result would look like this.

 1 - 35%
 2 - 20%
 3 - 30%

The final display would look like:

 1 - 100%
 2 - 100%
 3 - 100%
 
 The number of items determines how many C# tasks I should create and use from processing.

 Here are the issues / questions:

1. The items are not processed sequentially in the UI.
2. If I put in a large number like 1000 it only displays when the work is done.
3. Also with the large number like > 100 then the progress bar will sometime display on items = 101
4. The UI seems un-responsive on a large …
0
Hello EE,

In vb.net, I have a dictionary(Of Date, String).
Looks like this :

01/01/2018         Robert
01/02/2018         Steve
01/03/2018         Jenny
01/04/2018        Paul
01/05/2018        Veronica
etc
etc
etc
03/11/2019         Jenny

Open in new window



With this, in marketing we have some code that, if let's say as of now, if Jenny still was not picked up with our system, she will be in a list like this :

Jenny  - 90 days
robert - 56 days
Phil - 42 days
Catherine - 41 days
etc
etc
etc

Open in new window


meaning, its been 90 days that Jenny was not picked up by our system in marketing.
if tomorrow she gets picked up, she will be removed from the list and if the others were not picked, it will go like this :

robert - 57 days
Phil - 43 days
Catherine - 42 days

Open in new window


so Jenny is not in that dictionary(Of string, Integer) any more, but the others are and their days has been increased by one.


so all this works well.

My question is :   If I would like to check the history and the past, "who was picked up every week for the whole year", without manually writing it on a paper, how can I do it in vb.net ?
You see, we keep everything in the first dictionary I showed on top. the dictionary (Of Date, String) I have all the picks.

I would like to retrieve in the past, by week who was picked
so maybe in one week there is just 1 .. maybe in one week there are 3..
Because when it picks days goes to "zero" I have a hard time in vb.net, linq, and so forth, to do a function that goes back in time and read all this

can you help ?
0
I want to upload a local file into a remote file using C# SSH.NET library using SFTP client. I am able to do that in the parent directory , but when I want to upload file in a child directory , It is returning null .
My remote directory structure is /xyz/abc/finaldir . i want to upload a file in finaldir . That is not working . It is able to read xyz directory and abc directory and not finaldir.
When i try to change directory to /xyz/abc/finaldir for SFTP client It is throwing error telling "file not found"
Please help me !
0
How can I get / retrieve all members of a specific Sharepoint group with C#?
For example I have the Sharepoint group "Visitors" and I need all members of it respectively their e-mail adresses.
0
How to read multiple result sets from edmx? Edmx is always returning first result set. How to Fetch all result sets ?
0
Hello Experts,
In a web from I am trying to get confirm window stating "All the selected rows will be deleted, would you like to continue?".  I need two buttons "Yes" and "No".  All the above should happen when I click a "Delete" button on the screen.  Please help.

Thank you very much in advance.
0
Hi there, I am using C# wpf and trying to operate on a rich text finding and replacing words and formatting them in bold italics etc by using code behind. What is the simplest way to do it as I have read many complicated options and can't decide on one. Thanks.
0
Hello,
 I try to send messages to lock screeen  in windows 10 through my uwp application

according to this

I have create on button click event

 private void button_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Toolkit.Uwp.Notifications.TileContent content = new Microsoft.Toolkit.Uwp.Notifications.TileContent()
        {
            Visual = new Microsoft.Toolkit.Uwp.Notifications.TileVisual()
            {
                LockDetailedStatus1 = "Meeting with Thomas",
                LockDetailedStatus2 = "11:00 AM - 12:30 PM",
                LockDetailedStatus3 = "Studio F",
              

                TileWide = new Microsoft.Toolkit.Uwp.Notifications.TileBinding()
                {
             

                }
            }
        };

        var notification = new TileNotification(content.GetXml());

        TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
        }

Open in new window


but nothing happens when I click the button no errors no message. I have declare my app so to be used on background in Package.appxmanifest and I have also select
Control Channel, Push Notification and Timer in Declarations.

Any idea or other way to send notification to lock screen?

thank you!
0
Hi, I need to know how to force close one window from another in WPF.
I have one window,splash screen with do some background work. When it finish do all it have to it have to disappear and new window have to opens.
I use following code to do that:

MainWindow main = new MainWindow();

main.Show();
this.Close();

Open in new window


It works always on PC on tablet it works only one time after program was installed or tablet restarted,
Second time main window shows with splash screen over it.  Because the splash screen give to some global variables values that make possible to run Main form
I suspect the this splash screen not closed when application close. I close the application from main window:

Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
Application.Current.Shutdown();

Open in new window


It is very difficult to debug because the problem is visible only on tablet not on PC.
Because of that I think I have to force closing of Splash screen on some way
0
Here we go again...

So, for some reason, in the equation below the left side is considered an object and the right a decimal.

myWS.Cells[49, col].Value += myRecordSet.Fields["amount"].Value;

Is there any way to accomplish the feat above in C#?
0
I have this datagridview filled with a dataset using C#.  The grid is designed to display up to 12 rows. In the screenshot you will see how it looks when there are less than 12 rows. Can anyone provide suggestions or provide that would illustrate how to fill in the extra rows with blanks  so the grid will allows appear full? Let me know if you want to see my code.
JobLinker.png
0
I have a code in java and need to write it in C # please help me. Thank you

import org.junit.Assert;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class BrowserProfile {
    public static void main(String[] args) throws Exception {
        BrowserProfile bp = new BrowserProfile();
        //TODO replace with existing profile ID. Define the ID of the browser profile, where the code will be executed.
        String profileId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

        //Define DesiredCapabilities
        DesiredCapabilities dc = new DesiredCapabilities();

        //Instantiate the Remote Web Driver to connect to the browser profile launched by startProfile method
        RemoteWebDriver driver = new RemoteWebDriver(new URL(bp.startProfile(profileId)), dc);

        //Perform automation
        driver.get("https://multilogin.com/");
        Assert.assertEquals("Multilogin - Replace Multiple Computers With Virtual Browser Profiles - Multilogin",driver.getTitle());
        driver.quit();
    }

    private String startProfile(String profileId) throws Exception {
        /*Send GET request to start the browser profile by profileId. Returns response in the following format:
        '{"status":"OK","value":"http://127.0.0.1:XXXXX"}', where XXXXX is the 

Open in new window

0
I have a c# asp.net application that needs to play 10 videos. Each video will need to be started by the user pressing the next button. Once a video ends then I need to write to the database that user completed the video.   I have setup  a Ajax control with a timer for the length of each video.   Once the timer fires, then I want to stop  the video from looping, record to the database the user id  and the video id.  Then when the user presses the next button start the next video.
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).