Most voted "c#" questions
This tag should be used when the question refers to some resource, information or problem related to the C#language. C# ("C Sharp") is a multi-paradigm programming language that has strongly typed variables, is imperative, declarative, functional, generic, object-oriented and component-oriented, which are designed to be executed in . NET Framework.
Learn more…13,899 questions
Sort by count of
-
2
votes4
answers766
viewsHow do I capture only the last 2 digits of the current year?
How do I capture only the last 2 digits of the year in function DateTime.Now.Year.ToString()? I need to do a validation, for example, if the year is 2019, I need you to compare only 19, I will not…
c#asked 5 years, 7 months ago Jonathan Igor Bockorny Pereira 111 -
2
votes1
answer6570
viewsPath access error denied
I am with a program created in Visual Studio / Windows Forms. In it access the following file to get some information: 1st Code (works normal) StreamReader file = new StreamReader(@…
-
2
votes1
answer121
viewsIoc with Web Service
I need to create a WS with Ioc. I created a new Web project with Web API dependencies ; I added a Web Service (asmx); I installed the Simpleinjector; The code went like this : [WebService(Namespace…
-
2
votes0
answers313
views(C#) - Receive a date from the Console, and return if the date received is Considered a Business Day? Consider Holidays
The user will enter a date (DD/MM/YYYY), and the Program must return whether the date day is useful or not. I’ve been part of the code considering Weekend (Saturday and Sunday) not useful. I want to…
c#asked 5 years, 7 months ago Rebeca Nonato 1,163 -
2
votes1
answer292
viewsplace Custom EN Message in required field
Assigns Required="true" in a password field, but the message is in English, as seen in the image below: I wanted to personalize this message by leaving it in PT-BR <div class="form-group">…
-
2
votes1
answer44
viewsDoubts about Sessions and Roles
I have a controller responsible for doing the Login part, configured on web.config to use the <authentication mode="Forms"> <forms loginUrl="~/Usuario/Login" timeout="30" protection="All"…
-
2
votes1
answer108
viewsError while logging in using Facebook
Trying to login through facebook I come across the following error: Server Error in Application '/'. Undefined object reference for an object instance. Description: An untreated exception occurred…
-
2
votes1
answer53
viewsDifference between Executequery, Sqlquery and Executesqlcommand
What is the difference between Executequery, Sqlquery and Executesqlcommand? When I know which one to use?
-
2
votes1
answer625
viewsGet specific login data through facebook
I am seeking to implement authentication through the facebook. Where I want to get more data audiences. I already have the default authentication set up. But I need something else, because it only…
-
2
votes1
answer1326
viewsHow to validate a field To accept only Letters/Numbers using Regex
I am creating validations for every Property of my classes. I am using a component called AbstractValidator. Example: protected void ValidarChamadaTipo() { RuleFor(p => p.ChamadaTipo)…
-
2
votes2
answers53
viewsSave Status Code in variable and check
I need to save Statuscode and do a check. I have the following code: using (HttpResponseMessage response = await httpClient.GetAsync(UrlApi)){} When I do that: var teste2 = response.StatusCode; the…
-
2
votes1
answer60
viewsAuthenticating user by AD returns server user instead of local user
I have a web application that validates the user logged in to the machine, loads their permissions and opens the screens you are allowed, without using login screen. Caught the user with…
-
2
votes0
answers186
viewsHow to configure Owincontext Authentication in Simpleinjector 3.3.2?
In my current application I use Simpleinjector 3.2.0 with a similar configuration to this: var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();…
-
2
votes1
answer65
viewsString Connection to access sql remotely
I have an SQL SERVER database on one desktop and I’m making a program on another PC that will access that database. I wanted to know how to mount my string Connection to access the database…
-
2
votes1
answer694
viewsMult Mapping Dapper
I am having problems with Mult Mapping of Dapper, when I try to execute the following query is not mapping the object ids select is this: var sql = @" SELECT ofi.id_oficina, ofi.codigo, p.id_pedido,…
-
2
votes1
answer90
viewsHow to get the date and time of the machine to create a folder?
Hello! How best to get the date and time of the machine using C# and create a folder with the format 'DD/MM/YYYY HH:MM:SS' ensuring you never have two folders with the same name?
c#asked 5 years, 7 months ago Ronison Matos 313 -
2
votes1
answer227
viewsHow to send an Authorization TOKEN and parameters to perform an INSERT in my API?
My API works correctly. I can enter data into the database through it with POSTMAN, but I would like to do this in c#. This second image is from the creation of a token of mine.…
-
2
votes2
answers254
viewsProblem calling Virtual Keyboard - Winforms
I have a button that when clicking the virtual keyboard of windows is called. Process.Start("osk.exe"); By clicking the button an Exception is triggered: System.ComponentModel.Win32Exception: 'The…
-
2
votes1
answer77
viewsHow to upload multiple images to Cloudinary?
I use Cloudinary to upload files to the cloud. The following code works with 1 image, example: var uploadParams = new ImageUploadParams() { File = new FileDescription(@"C:\Users\Matheus…
c#asked 5 years, 6 months ago Matheus Miranda 5,375 -
2
votes1
answer1551
viewsThere is no Viewdata item of type 'Ienumerable' that has the key 'Categories'
I have a problem with dropdownlist. I populated it with information that was on my DB. Code of controller: public ActionResult NovoProduto() { ViewBag.categorias = new SelectList(db.Categoria,…
-
2
votes1
answer65
viewsSave and update entities
or personal I am trying to give an improved in my generic method that adds and updates, follows the code: public void InsertOrUpdate(T entity) { if (entity.Id == 0) {…
-
2
votes1
answer278
viewsInserting and updating data in N-N tables (many to many)
I’m having trouble saving in a relationship of many to many, follows my model: public class Pessoa { public int id { get; set; } public string descricao { get; set; } public ICollection<Conta>…
-
2
votes1
answer124
viewsDisplay text coming from the database under @Html.Actionlink()
Well, I have the following scenario: I make an appointment at database and I bring a IEnumerable<> to the View: <section class="container"> <article class="row"> @foreach (var item…
-
2
votes1
answer261
viewsHow to change the voice genre of Microsoft.Speech.Synthesis synthesizer?
I’m developing a voice recognition and synth program using microsoft Speech and system.Speech, but the female voice is used by default. Is it possible to switch to the male voice? I used the command…
-
2
votes2
answers1639
viewsHow to Instantiate an Object in C#
How do I instantiate an Object in another class? I’m trying this way: GameObject Cozinha = new GameObject("CenaCozinha"); CenaCozinha coz = Cozinha.AddComponent<CenaCozinha>(); But I believe…
-
2
votes1
answer293
viewsUse select top to declare a variable
I wanted to assign the value of the last item registered in the table alu_cod, but the query returns me error after the @total =: declare @total int select @total = SELECT TOP 1 * FROM Alunos ORDER…
-
2
votes1
answer361
viewsWPF using MVVM - Whose responsibility is it to open a new window?
In MVVM we have Views, Viewmodels and Models. All the business logic of my application is in models, where I use the viewModels to manage them, in addition to Binds and commands that are sent from…
-
2
votes1
answer831
viewsHow to select a select using the ado.net Entity Framework
I’m developing a system in ASP.NET MVC which uses as standard the Entity Framework for data access, but I am in need of a select on another select, and I don’t know how to do this with Entity. The…
-
2
votes1
answer62
viewsPrint a list according to the number of labels
My C# Console Application has a list of 7 items in all, and you need to print these items on a label. By default each label fits 5 items. I’m not able to print the items according to the amount of…
-
2
votes1
answer62
viewsString search in database using Linq C# wpf
I have a bank and I want to run a search in the name field, but I also want the customer to be able to search for parts of the string or even with uppercase and minuscule letters. by the time my…
-
2
votes2
answers306
viewsAny ASP.NET MVC solution for SQL injection?
I have in the application a code that validates the data entry, adjusting according to what is necessary, this would be considered a good or a bad option? public static string ValidaDados(string…
-
2
votes1
answer95
viewsQuery using Entityframework why the performance variation?
I have the following querys using Linq to Object: _Context.GerenciaTransacao.Where(x => x.Placa == "LUN1320").ToList(); in this query, the results return in 100ms. and string placa = "LUN1320";…
-
2
votes2
answers108
viewsCheck if call came from API (.Net Core) or MVC
I have some applications that need to share the same Repository (Class Library). The Repository project is created and working, with MVC applications. The problem is that it searches for the…
-
2
votes2
answers593
viewsC# - High memory consumption
I’m having memory consumption issues with an application that receives real-time news alerts. Whenever a news arrives, when opening this news, the memory consumption grows, but does not decrease in…
-
2
votes1
answer1164
viewsProblems trying to send email via smtp server
I am developing an application which sends emails via smtp.gmail.com server. When I am connected to a common network, it works perfectly. But, by the network of my company occurs the following…
-
2
votes2
answers1383
viewsPick up a selected item on Dropdownlistfor using an ASP.NET MVC Viewmodel
I am trying to register a Subcategory that needs a Category. I have Subcategoriaviewmodel, where I created the fields public IEnumerable<CategoriaViewModel> Categorias { get; set; } and public…
-
2
votes3
answers73
viewsMark All Checkbox in a groupbox
I have a program that in a groupbox has several checkbox, as there are many and I thought of making a button to select all at once, to be more practical, but there arose a doubt, as I can do when…
-
2
votes2
answers582
viewsIs it possible to run an . EXE application from a Windows Service?
This is an excerpt from the code: protected override void OnStart(string[] args) { Process.Start(@"C:\path\<file.exe>"); } protected override void OnStop() { } I wish I could run a . exe…
-
2
votes1
answer72
viewsRun fast things synchronously and time-consuming things asynchronously?
Usually, on . NET, I run things time-consuming asynchronously so as not to stop the thread visual. In a simple example, if I have a loading in the UI, should lengthy things be executed without…
-
2
votes1
answer237
viewsWhat is Guidattribute for and why?
I know the GUID is a 'unique' identifier, but I don’t see why your attribute application, as in the example below: [GuidAttribute("C281C7F1-4AA9-3517-961A-463CFED57E75")]…
-
2
votes4
answers60
viewsRemove null fields from a model that receives a list
I need to remove all null fields, which comes from a list of Phones, I tried to do it this way, but unfortunately it didn’t work: model.Phones = model.Phones.Where(x => x.Phone != null &&…
-
2
votes0
answers179
viewsString conversion error in Jsonarray - Volley Android method
My application receives a Jsonstring via web service from a C#API as listed below: [{ "LimiteCredito": 123.00, "PessoasFuncionarioId": 16, "Id": 12, "Nome": "Cliente PF A", "DataEdicao":…
-
2
votes1
answer38
viewsBuilder is coming empty
I am making a program in Asp net web apllication, but when I try to communicate the controller with the service the constructor this null saind, the dependencies are already configured in the…
-
2
votes2
answers462
viewsCopy excel extension files from various subdirectories with ssis
I To head banging on finding the solution to copy excel extension files from multiple subdirectories with ssis. I tried to get the foreach loop container to do it but I couldn’t, then they passed me…
-
2
votes2
answers186
viewsHow to recover a string from another page in Xamarin?
I’ve seen several examples of how to open a page by sending a string to it but I wanted an example of how to do the opposite, open a page and it returns a string when it is closed. My life is more…
-
2
votes1
answer134
viewsCreate a background server
It is quite simple, this code works, but only once, after the first time it is started no other request is answered, as if after it runs once the Streamsocketlistener stops. public void…
-
2
votes1
answer359
viewsHow to reset the Datasource property of a Datagridview and not delete the Header columns?
I’m filling my Datagridview with a list of objects, but when I fill the grid for the first time it’s all right. When Seto the Datasource property is null, the grid columns are deleted. There is the…
-
2
votes1
answer1216
viewsNon-static Method error requires a destination. '
I have a little problem and I need your help to help me solve it. How the error is occurring: Basically it is occurring, when I click on a button to open a modal to bring the information I want…
-
2
votes1
answer835
viewsUpload images to Asp net core 1.0
Oh guys I’m having a doubt I’m new in the . net, I learned in a course in Asp net mvc 5 so I would need to take that upload code and turn to Asp net core if you can help I am grateful. [HttpPost]…
-
2
votes1
answer362
viewsSave selected radio button option for future query
I wonder if you can save in one DataTable (or something like, to be consulted later) information that a radioButton was clicked. I am making a simple program for a client to report three information…