Posts by Tiago S • 4,234 points
136 posts
- 
		1 votes1 answer249 viewsA: Error return method "public async Task<string>"The error in this line is because you need to use keyword await before calling the method. Literal1.Text= await ObterEmocoes(imageFilePath); For this you need to mark the method Button1_Click with… 
- 
		4 votes2 answers84 views
- 
		1 votes4 answers1120 viewsA: Error Deserialize Json in C#TemplateThis happens because your Json is mounted different from your conversion What your json should have is a list of objects of the type Comanda. Below follows the correct Json: [ { "status": "Produzido… 
- 
		1 votes2 answers672 viewsA: How to create folders within the program’s own subfolder?Suppose your program is on the following path C: Users Jhonsnow Documents GOT.exe For the program to check for the folder inside the GOT folder if(!Directory.Exist("Downloads"))… 
- 
		2 votes3 answers68 viewsA: Error in if ultimalizationThere is a logic error there, Count will always be 0, as it is being initialized within the for loop The correct is: int SePar, SeImpar, cont; SePar = 0; SeImpar = 0; cont = 0; for (int i = 0; i… 
- 
		2 votes2 answers1703 viewsA: How to get information from an App.configYou need to open the configuration file first ConfigurationManager.OpenExeConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); Assign the reading to a variable and make the… 
- 
		1 votes1 answer172 viewsA: How to delete lines from a datagridviewTo hide the addition line of new lines, go to the properties of datagridview and Set Allowusertoaddrows=false;… 
- 
		1 votes1 answer182 viewsA: How to serialize a color with Json?Using the class JavaScriptSerializer the color is serialized, but when it comes to deserialize it cannot create the objects again, now using its own library to work with Json, the Color structure is… 
- 
		1 votes2 answers95 viewsA: Recovers data with Request.QuerystringThere are some errors in your code. These low fields do not exist in your form, for them to exist you must create an input or select and add the attribute name and set a name for the element.… 
- 
		3 votes1 answer423 viewsA: How to print accent on a Console Application project . NET CoreTo be able to print accents it is necessary to define the encoding of the output of the console, to this add Console.OutputEncoding = System.Text.Encoding.UTF8 at the beginning of your code. Thus… 
- 
		2 votes1 answer503 viewsA: How to write an asynchronous method?You can use the class Task public async Task AguardarContadorAsync() { int retorno = await Task.Run(()=>Contar()); } As you can notice you need to add Keyword async in the signature of the… 
- 
		1 votes1 answer480 viewsA: Get error message in Httpclient PostUsing the library Htmlagilitypack and using the Xpath to capture the div you can get the contents of it HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();… 
- 
		4 votes1 answer2356 viewsA: The percentage returns me zero in c#What happens is that you are doing the operation with integers. To get the percentage always do the division by one double or float. Example: (cont_f / (double)cont) * 100 If you want to do the… 
- 
		2 votes2 answers246 viewsA: String for Keyvaluepair using LINQUsing the Formula you can use this way: var texto = "N1N2S3S4L5L6O7O8X"; var keys = texto.Zip(texto.Skip(1), (Key, Value) => new {Key, Value}). Where((pair, index) => index % 2 == 0) .Select(k… 
- 
		1 votes1 answer308 viewsA: Generic Method for REST QueryThis mistake is making because it’s just coming back: {"codigo": "320-1", "name": "Zer", "key": "320"} In the above case the API is coming back an object. In order not to make the mistake, the right… 
- 
		6 votes4 answers362 viewsA: How do I skip the "Finally" block, in C#, when the exception is generated?It doesn’t make any sense that what you’re wanting, Finally, is for you to perform the necessary logics in case the block try whether or not you can do your job. For example You open the connection… 
- 
		1 votes1 answer379 viewsA: Do not go to another FORM1 while open FORM2 esiverYou can use . Showdialog(); Example: Form2 form=new Form2(); form.ShowDialog(); Until the user closes the Form2 screen, he will not be able to do anything on the Form1 screen… 
- 
		1 votes1 answer9195 viewsA: httpclient - Webexception: The underlying connection was closed: The connection was closed unexpectedlyYou need to add at least one User-Agent clientAPI.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Mozilla", "5.0")); See the final code static void RunAsync() { using (var clientAPI… 
- 
		2 votes2 answers91 viewsA: How to make the code not catch the ASCII Code from a variable?You can make the conversion from char to string, so you can get the real value and then convert to integer int j=int.Parse(bin[i].ToString()); 
- 
		3 votes2 answers689 viewsA: Call for generic methods in C#You call the method like any other by passing the type array T Below I created a class called Pessoa that I use in class MinhaClasse where I call the method you created by passing the instances of… 
- 
		0 votes3 answers55 viewsA: Automatic punctuation in the lines of a Multiline TextboxYou can use regex and replace string pattern = @"\s+\n"; string input = @"Isto é a primeira frase Isto é a segunda frase Isto é a última frase"; Regex.Replace(input,pattern,";\r\n")+"." Exit: Isto é… 
- 
		6 votes2 answers2570 viewsA: IIS lists directory instead of opening pageYour IIS is missing some resources needed. To add these features: Go on enable and disable windows service Afterward Internet Information Services Word Wide Web Services Resources for Application… 
- 
		0 votes2 answers1104 viewsA: Validate inputs in form with regular expressionsTo validate the name you can use this regex: /^[\p{L}\s]+$ On the phone /(\d{3}|\d{2}|\(\d{2}\))\s*(\d{9}|\d{8}) And to email /^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;… 
- 
		5 votes1 answer3473 viewsA: How to publish website made in Visual Studio?To publish a website in Visual studio 2017 Right-click on your project and then click Publish Then choose a Folder and give a path to the folder or leave the pattern and then click Publish To… 
- 
		0 votes2 answers3552 viewsA: Add values to a C#listWhat you can do is create a reading method to assist you with this table data one way to do this is by using the params to pass the columns separated by ,: private List<string>… 
- 
		3 votes2 answers116 viewsA: Find attribute value with regexThe simplest way you can use it is like this: feedtag="([^"]*)" This way he picks up everything inside the quotes after a feedtag= See working: https://regex101.com/r/BwibaW/2… 
- 
		1 votes1 answer2388 viewsA: How to download file via $.ajax()A solution would be to generate a temporary download link and make a GET request Instead of returning a Filestreamresult, you return a Json with a key [HttpPost] public ActionResult BaixarConta(int… 
- 
		1 votes2 answers281 viewsA: Send data to an Actionresult from a Controller other than the current oneJust use @Url.Action() The first parameter is action and the second the controler, that is to say, @Url.Action("ACTION NAME","CONTROLLER NAME") Using $.ajax() would look like this: <script… 
- 
		2 votes1 answer100 viewsA: Why is the Zipfile function not working?You need to add the reference System.IO.Compression.FileSystem in your project Source: MSDN… 
- 
		2 votes1 answer37 viewsA: Regex - Recovering Property from Pre-formatted FileThe problem is that some indices are different from the first and the fourth. Indexes 2,3 and 5 have spaces between text, which regex cannot match Down with the regex you can catch… 
- 
		4 votes3 answers351 views
- 
		3 votes1 answer335 viewsA: Get properties of a class with condition. C#You need to check if the property implements the base interface IEnumerable pais .GetType() .GetProperties() .Where(x => x.PropertyType == typeof (string) || !typeof… 
- 
		2 votes3 answers764 viewsA: Error In Modelstate ValidationThis is wrong, you can’t do it this way: string erros = ModelState.Select(x => x.Value.Errors).Where(y => y.Count() > 0).ToString(); You are turning a collection into a string and when you… 
- 
		1 votes3 answers1314 viewsA: Format Field C#You can use it like this: 1000.ToString("0,0",new System.Globalization.CultureInfo(("pt-BR"))); In this case you need to pass the instance of CultureInfo of en-BR for it to format in the Brazilian… 
- 
		4 votes4 answers3416 viewsA: How to do a search to know if a string is inside a vector in C#You can use Linq to find as well string[] nomes = { "misael", "camila", "fernando" }; if (nomes.Count(x => x == txtbusca.Text) > 0) MessageBox.Show("nome encontrado"); else… 
- 
		0 votes1 answer143 viewsA: Execute mongoimport command via c#You are just opening cmd and navigating to the bin folder of Mongo An example taken from Soen public bool importCsv(string filepath, string collectionName) { string result =""; try {… 
- 
		0 votes2 answers200 viewsA: Error validating with RegexPerhaps this regex can serve you string pattern = @"(?i)(,|\.)?[^a-z0-9]\s|(\/|\-)"; Using Regex.Replace() you can remove the special characters. private static string PreprocessingText(string… 
- 
		1 votes2 answers110 viewsA: Help with threards systemAn easier way to work with threads is with Task Your method would look like this: private async void GeraRelatorio_Click(object sender, RoutedEventArgs e) { await Task.Run(() =>… 
- 
		1 votes2 answers963 viewsA: I cannot apply Encoder to the text to correctly display "ç, accents, other special characters"I made an application here and I circled on a Windows 10 machine in Portuguese and another with windows 10 in English, and on the two machines I got the same result. When I just made the line below:… 
- 
		5 votes3 answers625 viewsA: How to treat Nullreferenceexception with LambdaWhat is occurring is that you are trying to access a property of a null object p.GetCustomAttribute<DisplayNameAttribute>().DisplayName != null It is right to check whether the… 
- 
		1 votes2 answers304 viewsA: Pick all fields of a class using Lambda + Group ByYou need to take the first item from the group and get the id. var result = (from p in produtosCompletos group p by p.descricao into g select new produtoCompleto() { idUnidade = g.First().idUnidade,… 
- 
		5 votes1 answer7455 viewsA: How to use group by in LAMBDAThere are two ways to do it: Straight into the Linum var result=from p in produto group p by p.descricao into g select new {descricao=g.Key,count=g.Sum(x=>x.quant)} or with Extended Methods var… 
- 
		2 votes1 answer29 viewsA: How to include if command to add a new object to a list?You can use the ternary condition foreach (pessoa item in pessoa) { List<pessoaT> pessoasT=new List<pessoaT>() pessoasT.add(new pessoaT() { nome = item.nome, idade = item.idade,… 
- 
		2 votes1 answer745 viewsA: Why doesn’t Webbrowser show us reCaptchas?You need to set the Webbrowser version to 11, so implement the method below in your main form: Don’t forget the using Microsoft.Win32; public void VerifyVersion(WebBrowser webbrowser) { string… 
- 
		12 votes3 answers5878 viewsA: Creating a List<> from a Json C#In visual studio you can transform any string in the pattern json in class C#, just follow the steps below: Edit > Past Special > Past JSON As Class Class generated by visual studio public… 
- 
		2 votes1 answer162 viewsA: Load the comboboxImplement the method below in your form and when you load the saved data, pass to the selected fuel method: private void SelecionarTipoCombustivel(Combustivel combustivel) {… 
- 
		5 votes3 answers184 viewsA: Search in StringYou can try with regex import java.util.regex.Matcher; import java.util.regex.Pattern; final String regex = "[#]\\w*\\d*\\W\\s*"; final String string = "oi tudo bem como vai #01?"; final Pattern… 
- 
		0 votes3 answers1401 viewsA: How to access object created by another thread?To access an object from another thread, you must give the Invoke. The easiest way to give one Invoke is: Examples Inside your Windows Form: this.Invoke(new Action(()=>{ /* TODO: Seu código aqui… 
- 
		2 votes2 answers427 viewsA: How can I detect if the value of a textbox has letters?You can use the code private void textBox_KeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = !((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >=… 
- 
		8 votes1 answer107 viewsA: Compare Strings by format not by valueUsing the Regex.IsMatch() you can check if a string is within the expected pattern, below follows an implementation. Don’t forget to include the namespace System.Text.RegularExpressions Using…