.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Share tech news, updates, or what's on your mind.

Sign up to Post

In ASP.net is it possible to convert a text box to a label using code
0
Hi

In ASP.net I want a user to push a button on a website that runs code that sends the
web page as a pdf attachment, What VB.net code would I use to do this?
0
I am getting an error on a page that uses entity and Telerik for a webforms application that uses .net 4.0 because I am not able to update to later version of .net.  Had a different error when trying to use entity framework 6.0 and went down to 5.0 and that error is gone and site loads but now the page I am trying to add has this issue.  See errors below when page is brought up.  Not sure how to see LoaderExceptions when on a server.  No problems running on development computer with Visual Studio 2017.

 Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Open in new window


Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
   

Open in new window

0
This question is kind of a continuation of our previous question which was solved. This was the previous question: How to Edit an .aspx page: We have a new website and one of the pages when opened in a browser is like a form, and the boxes are not lined up correctly and the page is dark.
Is there a program that I could open up the page and edit it, such as lining up the boxes and making the page brighter? We have Visual Studio 2015 and when I open the page up in design view, I can align the boxes but when I save it, it doesn't keep the changes.
New question:
We've been able to edit this page with Visual Studio 2015 somewhat but now I'm stuck. We have a label on this page called "Amount" which spans 2 columns and is centered. We would like to be able to put the text "Total" to the left of the "Amount", kind of like below:
                                                             Total                                 Amount
Please see the code below, thanks for your help.
<td colspan="2">
                             <asp:Label ID="lblAmount" runat="server" ForeColor="Black" BackColor="White" Font-Names="Calibri" />
                        </td>
0
Hi,

I have this rest api request that returns a boolean value. Initially this value is always set to false but will turn to true within seconds (or up to a minute) . I need to do re-do or poll the request until the status of the value has changed from false to true and then, of course, stop the request(s) and continue.

What kind of methods can I use to make this happen.

Grateful for help and example code.

Peter
0
How do I add an image from resource to WPF form?

In Visual Studio I create a new project. I select: Visual C# | Windows Desktop | WPF App (.NET Framework)
Name of new project is "WpfApp1"

In Solution Explorer I right-click on "WpfApp1", select Properties

On left side I select Resources

I drag image file from File Explorer to the "Resources page". This adds the image to my resources. (Let's say the image file is "MyImage.bmp" and it shows up as "MyImage")

I set Access Modifier: change from "Internal" to "Public"

Now I would like to add this image to my MainWindow.xaml form:
<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Image Source="{something goes here}" />
    </Grid>
</Window>

Open in new window

What do I specify as Source for Image I'm my MainWindow.xaml file?
0
Hi,

I have these classes:

Public Class Party
    Public Property partyIdentifier As String
    Public Property email As String
    Public Property telephone As String
    Public Property role As String
End Class

Public Class Car
    Public Property registrationNumber As String
    Public Property registrationNumberMissing As Boolean
    Public Property model As String
    Public Property used As Boolean
    Public Property year As Integer
    Public Property mileage As Integer
    Public Property objectGroupType As String
End Class

Public Class Calculation
    Public Property cashPrice As Integer
    Public Property downPayment As Integer
    Public Property residualDebt As Integer
    Public Property creditTime As Integer
    Public Property interest As Double
End Class

Public Class Insurance
    Public Property monthlyCost As Integer
End Class

Public Class Finance
    Public Property contractType As String
    Public Property customerType As String
    Public Property customerLicenceType As String
    Public Property Parties As List(Of Party)
    Public Property car As Car
    Public Property calculation As Calculation
    Public Property profileId As Integer
    Public Property campaignId As Integer
    Public Property plannedDeliveryDate As DateTime
    Public Property insurance As Insurance
End Class

Open in new window


I'm now trying to build this as an object that I can serialize into json like this:
 If Not Page.IsPostBack Then
            Dim f As New Finance

            ' Basic
            f.contractType = "Installment"
            f.customerType = "Private"
            f.customerLicenceType = "SwedishDriversLicense"

            ' Parties
            Dim p As New Party With {
                .partyIdentifier = "8811119307",
                .email = "nordberg.peter@gmail.com",
                .telephone = "0854545656",
                .role = "Buyer"
            }
            f.Parties.Add(p)

            Dim json As String = JsonConvert.SerializeObject(f)
            Label1.Text = json
        End If

Open in new window


The problem is that I get an error that an object doesn't exist when adding an party item to the lost of parties as can be seen in below image.
 Objkect error
What am I doing wrong and how can I fix it?

Peter
0
I'm getting below error while compiling the below code

HttpClient' does not contain a definition for 'DefaultRequestHeaders'
HttpClient' does not contain a definition for 'GetAsync'

Project details:
Microsoft Visual C# 2012
.Net framework 4.5.2
Windows service

using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;

var client = new HttpClient();
 client.BaseAddress = new Uri(ConfigurationManager.AppSettings["uri-path-port"].ToString());

 client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
           

Open in new window


HttpClient' does not contain a definition for 'DefaultRequestHeaders'
HttpClient' does not contain a definition for 'GetAsync'

To fix this issue I  have tried the below  form package manager console:

Install-Package Microsoft.AspNet.WebApi.Client

I got this error:

Install-Package : Unable to find package 'Microsoft.AspNet.WebApi.Client'.
At line:1 char:1
+ Install-Package Microsoft.AspNet.WebApi.Client
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
0
Hi,

I need some help with a request in vb.net. In postman I've succeded to get it to work and I've added the screenshots below
Postman 1Postman 2Postman 3

Now I've used Restsharp (but any request will do) to try and connect through code:

 Dim username As String = "xxx"
        Dim password As String = "xxx"
        Dim client As RestClient = New RestClient("https://url")
        client.Authenticator = New HttpBasicAuthenticator(username, password)
        Dim request = New RestRequest(Method.POST)
        request.AddHeader("Postman-Token", "fa4aa5a9-0c7a-45ad-a8b1-24fd0ac75f8c")
        request.AddHeader("cache-control", "no-cache")
        request.AddHeader("api-version", "1")
        request.AddHeader("Authorization", "Basic xxx")
        request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
        Dim response As IRestResponse = client.Execute(request)

Open in new window


However I get this answer:
{"error":"unsupported_grant_type"}
0
(Even tho I've resigned, I still want to help the team out before I leave on Friday)...

Our code is MVC , C# with EF 6. The mid developer on the team is going on and on about adding IoC to the code, gut it out whatever , to add unit testing. He said IoC for unit testing because we don't have any unit testing in the solution.

What is he talking about?  It's not a huge solution and not a complicated project.

I found this
https://stackoverflow.com/questions/1465849/using-ioc-for-unit-testing

and this http://duanenewman.net/blog/post/better-unit-testing-with-ioc-di-and-mocking/

I know this an open question... but should he do this? Would it add complexity to the code that's already suffering from performance issues and is an old code....written 5 or 6 yrs ago.
0
How to add a reference to Microsoft.Web.Management.Server reference in my c# project?
0
Hi

I'm extracting links from html using HtmlAgilityPack  but i'm getting a lot of unwanted rubbish

I have a list of wanted hosts how might I filter the links against this list?

using System;
using System.Xml;
using HtmlAgilityPack;
using System.Text.RegularExpressions;

					
public class Program
{
	public static void Main()
	{
		var html =
        @"<body>
    <div class='content'>
      <div id='post_message_30829575'>
        <a href='https://example.com/foo/123adj'><img src='https://example.com/foo/123adj/thumb.jpg'></a>
        <a href='https://example.com/foo/bar'>Link to foo bar</a>
        <a href='https://wanted.com/foo/bar'>Link to foo bar</a>
        <a href='https://rubish.com/foo/bar'>Link to foo bar</a>
      </div>
    </div>  
  </body>";

        var htmlDoc = new HtmlDocument();
        htmlDoc.LoadHtml(html);
		string [] hosts = {"exasmple", "wanted"};

         var HTMLBody = htmlDoc.DocumentNode.SelectSingleNode("//body");
            foreach (var Node in HTMLBody.DescendantsAndSelf())
			{
				var linkNodes = Node.Descendants("a");
				foreach (HtmlNode linkNode in linkNodes)
				{
					HtmlAttribute link = linkNode.Attributes["href"];
					HtmlNode imageNode = linkNode.SelectSingleNode(".//img");
                                       // Don't need images
					if(imageNode == null)
					{
						Console.WriteLine("Link value: {0}", link.Value);
					}
				}
			}
		
		
	
	}
}

Open in new window

0
When using asp.net web forms or asp.net mvc and using a gridview or an html table holding a sql server table with large amount of records and you want to allow exporting of the data to pdf.
What solution or technology do you normally use to export the large amount of data to pdf quickly?
0
Hi,

I am having trouble to install .net framework 3.5 or 4.o  in Window 10 enterprise due to WSUS server we have.

Any suggestions are appreciated!

Thank you very much in advance!
0
Hi all
i got

cie as date
cie.ToString("dd/MM/yyy")

result

14/03/2019

I need

Jueves 14 de Marzo del 2019
trans

Thursday 14 of march of 2019

or some like that, the needment is that give me the day as text format
"thursday"

tsm experts
0
The code below works, but I don't need it to be long data.
I've tried replacing the "LONGTEXT" with "SHORTTEXT" but that just gave me an string error.

If strBomPartCount.Length > uintTableCurrentColumnCount Then
                oConn.Open()
                For columnIndex = uintOffSet To strBomPartCount.Length
                    oQuery = "ALTER TABLE PcbBom ADD COLUMN PnQty" & (columnIndex - 4) & " LONGTEXT"
                    oComm = New OleDbCommand(oQuery, oConn)
                    oComm.ExecuteNonQuery()
                Next
                oConn.Close()

            End If

Thanks in advance.
0
Hi,

I have following codes.
I have myCollection variable that contains all the Web elements.  I am using two paths using XPath and or('|') operator because I need different things from the objects that these two different paths gives.
From the elements from the first path(//div[@role='region' and //@my-label] ), I want to get Text properties.
From the elements from the second path(//button[@role='button' and //@my-label]), I want to get the values of 'my-label' attributes. (the Text properties for this elements are "")
After that, I want to put all these too myList<string>.
Obviously I am getting errors on my Linq query(at Select statement).
What's should I do to accomplish this?


public IReadOnlyCollection<IWebElement> myCollection => _driver.FindElements(By.XPath("//div[@role='region' and //@my-label]  | //button[@role='button' and //@my-label]"));

var myList = new List<string>();
myList = myCollection
                    .Select(a => a.Text or a => a.GetAttribute("my-label").ToString()) 
                    .Reverse() // Newest item first
                    .Where(a=>!String.IsNullOrEmpty(a))
                    .Where(b=>!String.IsNullOrEmpty(b))                              
                    .ToList();

Open in new window

0
Using Windows Forms

I have a tabcontrol , each page has a datagridview.  I know the  tab page name

tabData.SelectedTab.Name

let's say I have tabPage1  the datagridview on that tab is dgvPage1.   Now I want to get the selected row

int row = dgvPage1.CurrentCell.RowIndex;  


How can I do this if all I know about is the grid I want is   -- String  VariableName  =  "dgvPage1"  stored in a variable.

int row = (VariableName).CurrentCell.RowIndex;  
String Person = (VariableName).Rows[row].Cells[0].Value.ToString();
0
Hello,
I am getting below error :
 
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
   at System.Data.SqlClient.SqlBuffer.get_Int64()
   at System.Data.SqlClient.SqlDataReader.GetInt64(Int32 i)

Open in new window


This comes on line row[7] where it is assigning Date value. This is assigning to DataRow in Datatable , Please help.Thanks I checked there are data available in reader there is nothing like NULL for data. There is data present.


                    while (dr.Read() == true)
                    {
                        
                        if (Uid!= dr.GetInt32(0))
                        {

                            row = table.NewRow();
                            rectificationId = dr.GetInt32(0);
                            row[0] = dr.GetInt32(14);
                            row[1] = IdTest; 
                            row[2] = dr.GetString(1); 
                            row[3] = dr.GetInt32(2); 
                            row[4] = dr.IsDBNull(4) ? 0 : dr.GetInt32(4);                           
                            row[5] = dr.IsDBNull(6) ? string.Empty : dr.GetString(6); 
                            row[6] = dr.GetString(11); 
                         [b]   row[7] = new DateTime(dr.GetInt64(12)); [/b]
                            row[8] = new DateTime(dr.GetInt64(8)); 
                            row[9] = new DateTime(dr.GetInt64(9)); 
                            row[10] 

Open in new window

0
Hi

I have a few user settings in my vb.net project. The problem I am having is that they are not updating when I save them. The settings are set in user in the project properties. My code is:

        My.Settings.ServerIPAddress = txtServerAddress.Text
        My.Settings.ServerUserName = txtServerUser.Text
        My.Settings.ServerPassword = EncodeServerData(txtServerPassword.Text)
        My.Settings.Save()

The problem is in the following:

            If My.Settings.UpdateSettings = True Then
                My.Settings.Upgrade()
                My.Settings.Save()
            End If

I use this so that when a new version is installed I get the old settings. I need the best of both worlds the user to be able to change the settings and them being preserved when new versions are installed.

Any help would be appreciated

Nick
0
Hi All,


I want to develop a application for starting and stopping VMs , it will utilise Azure powershell . should I use powershell and wpf or c# and wpf, if I develop in c# the guide interface, can I call powershell commandlets? is c# more flexible for developing wpf guis than powershell?

thank you in advance,
kelly
0
Need Sitecore and .NET MVC practice site

I will be placed on a client location in a few weeks and at that time will be granted access to the existing Sitecore database. Until then, I need some hands on practice with Sitecore.

First, what is the correct term for a Sitecore file? It's not a database, but what term do you use to describe it?

I will be using Sitecore with .NET C# MVC.

I have Visual Studio installed and SSMS, but may need to put on SQL Server as well.

What can you suggest? I will also have no access to the source code until I am at the client location, so I just need something akin to a sandbox where I can play around. An existing, working MVC site with an integrated Sitecore demo database would be best.

What can you suggest?

Thanks
0
Have a vendor product CT FreightRater, an automated rating database used to calculate rates for loads we haul. We can enter hundreds of scenarios for rates like mileage, flat rate from point to point.
FreitRater recently did a changeover from running their WebService using XML, to using JSON. I have my JSON data conversion code ready, but need assistance setting up the front parameters that allow the HTTP URL, validation, etc.
In my RPGLE program, I use a product called RPG-XML Suite from Krengeltech. It supplies API's I can use to formulate my data into the JSON format, and that's working fine.
I can test through a program on the FreitRater Server called 'MultiRater'. This allows me to 'drop' in formed JSON statements to test against the rating database, and receive a response.
Unfortunately, FreitRater is unable to provide the specs for what these parameters are.
The only example I received from them to allow testing sending a RatingRequest example (C# .NET), is attached.

I'm also including the RXS_TransmitDS_t data structure used to 'send' to the FreitRater WebService in an attachment.

I need a 'translation' of sorts between the C# .NET example, to be able to  plug in those parameters to the RXS_TransmitDS_t data structure.

How-to-send-a-RatingRequest-Example-.txt

RXS_TransmitDS_t.txt
0
Hi,

I have an rdlc report in Legal papersize. I have set the report properties to Legal. The problem I am having is when I load it in to the reportviewer  and go to print the pagesize under page setup is always set to letter so it has to be changed manually. I need to be able to set the page settings in reportviewer programmatically so I can switch between letter and legal sizes via the code.  I have tried various things but nothing seems to affect the page setup dialog. What is the correct procedure to do this. I am coding in vb.net.

Thanks

Nick
0
Tips to mastering Sitecore

I have a rare opportunity to invest lots of time into learning Sitecore, in preparation for a job integrating Sitecore with a .NET MVC application. So, the more I learn now, the further I can go in implementing Sitecore.

What videos and topics can you suggest I did into to make the most out of this one month deep dive into Sitecore.

And what related technologies might I also consider?

Thanks
0

.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.