.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

Hi there.

I have some code suggestion made for C#, that I want to make in VB.NET. Some code is meant to be in the "IdentityConfig.cs". Where is that going in VB.NET?

Best regards

Ulrich
0
Hi there.

I'm finally starting to step up to .NET. I will use a present classic asp project and redo from scratch. I want to implement two factor authentication (e-mail), but I'm unsure if it should be done in C# or VB, AND if it's only possible in one of these?
I'm used to VB from the past with classic asp, so of course I would like to use that, but two factor authentication is a must, so I'll have to deal with C# if necessary.
I look forward to your input. I found this:
https://www.hanselman.com/blog/AddingTwoFactorAuthenticationToAnASPNETApplication.aspx
It appears as C# to me. Am I wrong?
If you know of better guides/help to implement two factor authentication, please let me know. :-)

Best regards

Ulrich
0
What's the best way to parse the following string into an object?
vbCrLf & "+COPS: (2,""O2 - UK"",,""23410"",0),(3,""vodafone UK"",,""23415"",0),(3,""EE"",,""23430"",0),,(0-4),(0,2)" & vbCrLf & vbCrLf & "OK" & vbCrLf
An example would be good!
Thanks
0
Having issues with cut off data inside my COM port buffer. I keep things open for  5 secs. but it seems like a couple times it cuts off the front end of the message.

How can I protect against that. I do not use a STX start message or any Checksum or CRC's.
0
Hello Experts,
In the code below,  what happens to the value of Output parameter parm[1] and variable returnId inside and outside the USING block in C#?  Please try to help.

 { using (SqlConnection connection = SqlHelper.GetConnection())
     
               parm = new SqlParameter[2];
               parm[0] = SqlHelper.CreatePerameter("@Id", SqlDbType.VarChar, sId, ParameterDirection.Input, 50, false);
               parm[1] = SqlHelper.CreatePerameter("@Error_Msg", SqlDbType.VarChar, 0, ParameterDirection.Output, 500, false);

               returnId = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnection(), CommandType.StoredProcedure, "usp_deleteRejectedItems", parm);
               strErrorMessage = parm[1].Value.ToString();
               intReturnId = returnId;
     }

    strErrorMessage = parm[1].Value.ToString();
    intReturnId = returnId;   

Open in new window


Thank you in advance for you time and help.
0
Hi
Following on from previous question

I have a TreeView and a ListView showing directory structure
The listView has Directories & files.

When I double click a Folder in the ListView how do I find the node in the TreeView and expand it replacing the contents of the ListView  similar to explorer

treeView1.Nodes  will only give you the Parent Nodes or in this case system drives

This Page suggest iterating through ChildNodes

In the full code bellow the bit  the handles double click is " ListView1_MouseDoubleClick"
When adding items to the ListView item.tag = the FullPath of the item e.g. "E:\\temp\\SubDir" or "E:\\temp\\SubDir\\MyFile.txt" I thought I could use this to find the TreeView.Node

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static DragDrop.NativeMethods;
using static System.Windows.Forms.ImageList;

namespace DragDrop
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopulateTreeView();
        }

        private void PopulateTreeView()
        {
            foreach (var drive in Environment.GetLogicalDrives())
     

Open in new window

0
I need to display birthdate value as age.

Examples:
DateTime bd1 = new DateTime(1, 5, 1);

string age1 = bd1.AsAge();

//output: 
// 1 Year, 5 Monthes, and 1 Day.

Open in new window


DateTime bd2 = new DateTime(50, 1, 30);

string age2 = bd2.AsAge();

//output: 
// 50 Years, 1 Month, and 30 Day.

Open in new window


The client asks for rounding the age value but she does not give me the rules.

Is there any ready component to use instead I reinvent the wheel?

Thanks
0
My Custom DGV returns zero for selectedRowCount.

        public int SelectedPatientId()
        {
            int selectedRowCount = dataGridViewEx1.Rows.GetRowCount(DataGridViewElementStates.Selected);

            int id = -1;

            if (selectedRowCount > 0)
            {
                id = int.Parse(dataGridViewEx1.SelectedRows[0].Cells["Id"].Value.ToString());
            }

            return id;
        }

Open in new window


using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using ECMS.Client.Desktop.Helpers;

namespace ECMS.Client.Desktop.Views.UserControls
{
    public class DataGridViewEx : DataGridView
    {
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Color BackColor
        {
            get => base.BackColor;

            private set => base.BackColor = value;
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Color ForeColor
        {
            get => base.ForeColor;

            private set => base.ForeColor = value;
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Font Font
        {
            get => base.Font;

            private set => base.Font = 

Open in new window

0
Hi
Following on from previous question

When loading directories in TreeView the  $Recycle.bin and System Volume Information directory  are shown See Picture
Clearly you don't want users to be clicking these

I thought about using a try catch block to handle the exception but then I thought it's probably better not to show them in the first place

The code snip bellow gives
Argument 1: cannot convert from 'System.IO.DirectoryInfo' to 'string' @ (d) 

Open in new window


        private void OnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode newSelected = e.Node;
            listView1.Items.Clear();
            DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
            ListViewItem.ListViewSubItem[] subItems;
            ListViewItem item = null;


            var Directories = nodeDirInfo.GetDirectories()
                         .Select(d => new { Attr = new DirectoryInfo(d).Attributes, Dir = d })  // error here
                         .Where(x => !x.Attr.HasFlag(FileAttributes.System))
                         .Where(x => !x.Attr.HasFlag(FileAttributes.Hidden))
                         .Select(x => x.Dir)
                         .ToList();
            foreach (DirectoryInfo directory in Directories)
            {
                item = new ListViewItem(directory.Name, 

Open in new window

0
I have a c# application

I am trying to get the unique ID  for the "C" drive of my PC  with the Code  below

private void button1_Click(object sender, EventArgs e)
        {
            //txtID.Text = getUniqueID("C");
            txtID.Text = MachineIdProccesor.GetUniqueID("C");
            
        }

Open in new window


The code that actually gets the ID was initially in the same form (under the Click event)
The code ran perfectly with the now commented line above

I now tried to move the same code to a class library  (DRYDemoLibrary)  to make it accessible from  other  parts of my application
with the uncommented code above.

The code is shown below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Management; //Need to manually add to the References
using System.IO;

namespace DRYDemoLibrary
{
    public class MachineIdProccesor
    {
        public string GetUniqueID(string drive)
        {
            if (drive == string.Empty)
            {
                //Find first drive
                foreach (DriveInfo compDrive in DriveInfo.GetDrives())
                {
                    if (compDrive.IsReady)
                    {
                        drive = compDrive.RootDirectory.ToString();
                        break;
                    }
                }
            }

 

Open in new window

0
Greeting,

I am putting together a little program that I want to Display and Modify a PDF file. I want to display the PDF  from within my Application before and after I modify the PDF.
I have all the code working just fine BUT only when I run the code in DEBUG mode in VS 2017. Once I create the RELEASE version and install it the embedded PDF viewer will
will not work.

I am using  the  AxAcroPDF OCX, control and I am looking  for some help in understanding why the control will not work once 'Released'.

As a side note I am using PDFSharp and iTextSharp  to manipulate the PDF files.. I will post any and all code that may be necessary to resolve the 'Release' code problem.

Thanks in advance
Rick
0
Manual Creation of ASP.NET Code Behind Page... ?

Main Page: TCC.aspx

Code Behind Page: TCC.aspx.vb (see attached file)

Two Issues...

A. How do i Correctly Move The Code From TCC.aspx to my codebehind page... I am missing something ?
....When i move the code over and namespaces over i think i am missing a header i think or have the code wrong cause it is all red lines..
....I am using VStudio 2017 and it did not have a checkbox choice to create code behind page ?

and...

B. Can I change this to C# later (when i have it correct)  by just changing the Page Language to C# and rewriting the code behind modules in C# ??

TCC.aspx
<%@ Page Language="VB" AutoEventWireup="false" Codefile="TCC.aspx.vb" Inherits="TCC" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.Page" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.data.OleDb" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Register Assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.EnableViewState = False
        DateToday.Text = 

Open in new window

0
Hi
I'm trying to work out how to do drag and drop on a form
I've worked out how to get the path of folder dragged from explorer into a text box

I now need to drag between ListViews and from Explorer

My form has 4 elements

1 Text box => FolderTxtBox
2 ListViews =>  MoviesLV & ImagesLV  (AllowDrop = True)
1  Button => Rename (Code not yet implemented)

Basic Flow

On Dragging a  folder from Explorer onto FolderTxtBox a  list of movies and matching jpg's is shown in MoviesLV and any jpg's not used are shown in ImagesLV

I want to be able to drag a jpg from ImagesLV in to the Image Name column of MoviesLV
or
If this doesn't exist from Explorer

Form1
 The Code  bellow is based on this example

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows;
using System.IO;
using System.Collections;

namespace DragDropLV
{
    public partial class Form1 : Form
    {
        new HashSet<String> JpgFileEntries = new HashSet<String>();
        bool Mlv_mdown = false;
        bool Jlv_mdown = false;
        public Form1()
        {
            // link https://www.c-sharpcorner.com/article/imlememnting-drag-and-drop-in-listview-controls/

            

Open in new window

0
Hi

in a previous question Mike Tomlinson suggested I'd create a better UI using ListView on a form.

I've been looking at how to do this
creating-an-explorer-style-interface-with-the-listview-and-treeview is a good start but How do I add system drives

Also instead of using images for tree nodes how do you you use the system icons?

I found this page but it's written in VB not C#

Overview not part of question

So you get an idea of what my objective is, I need to choose jpg's realtion to video files

My thinking on the flow would be the user navigates (using treeView, or Drags a folder from explorer)

On clicking the folder node the icon changes to open and
ListView1 is populated with video files and any actual or potential (using RegEx) associated images
ListView2 would be Other jpg's in the same folder
0
I was up and running using Microsoft Visual Studio 2013, and had no problems generating a build or published web application.  I was upgraded to
Microsoft Visual Studio 2017 and now can still do a build successfully, and run a local copy of my application.  However, now when I attempt to
publish, the published version does not work and fails  I noticed in the published code apsx pages, the <% page directive has been corrupted.

Alll aspx. pages have corrupted page declaration. Inherit parameter has gibberish in it, and the codebehind has disappeared.

Any idea on how to fix this issue?  I got a copy of Microsoft Visual Studio 2013 and ran a publish and it was fine.  However, do not have a permanent
licensed copy of 2013 but I now have for 2017 but it won't publish.
0
How do you open SQL Standard and not Express.  

I know this is probably a simple question, but I cannot figure it out.  

I had SQL Express installed.  We now are licensed for SQL standard.   When I open SQL management studio I believe it is still opening Express.  How do I tell?  I want to open Standard
0
I've spent two days on this and no one at work knows Crystal Reports. I'm new at the job and to CR. I've used SSRS in the past.

I hope someone can help me with this. I'll go step by step.

1. I have a main report and some some reports. The datasource for them is datatables. I see the datatables being populated but the subreports aren't. I changed a datasource for one of them and I wonder if that caused the issue.

2. This is the Main Report and has "Transactions" subreport
r1.png
3. I changed the datasource to a new datatable for subreport Transactions
r2.png
4. I see the Database Fields.
r3.png
5. This is how I updated the Datasource for the subreport. The one marked X is the old one and I updated it to the new one..marked with circle.
r4.png
6. I see 2 datasources but I'm using the first one
r5.png
7. I checked the subreport and I see this. I don't think I need that checkbox to link to the main report. I tried it with and without the checkbox.
r6.png
8. I see the data when I step thru the code

r7.png
9. I don't see the data on the report
r9.png
I've tried lots of things; Populated the old datatable, copied the new datatable to old one, set the datasource in the code, cleared the datasource in code, assigned it again. I also added a test subreport and that didn't get populated either.

Is my option to delete the …
0
Try to run "dotnet ef migrations  add Initial"  to migrate the database and create database schema. However, it returns "Build failed" in Visual Code.

Where can I find more hints about what's wrong with the build ?

Thx
0
Hi,
I am searching a solution to get the multiple table set from stored procedure using edmx entity framework. I found the below solution but that uses ADO.net. Is there any approach/sample code to get dataset(multiple tables) from stored procedure without ADO.

https://github.com/KrisJohnstone/RandomCodeSamples/tree/master/MultipleResultSets
Below are the project specifications:
.Net Framework: 4.7.1
VS2017
SQLServer2016
MVC: 5.2
0
Looking for suggestions for a good DB to use given the archictecture of this application.

I have been given a pretty open ended choice to make so looking for reasons to use on dB over another.

Here is the environment:

I will be developing a web application using .net core.
I will be building a parallel deployment ..
1)  Traditional Azure deployment.  
2)  I will be using Docker in the future..so was hoping to put that planning in at the beginning of my design...but this initial rollout will just be using Azure in the private cloud.
3)  I will have some level of web api and microservices...to what extent I am not sure.
4) My front end so far I am leaning the latest Angular 7.

My company wants me to pilot something new so that rules out SQL Server versions or Oracle.

I am gussing this leaves me to Mysql or MariaDB.  PostGresSQl

Or

some version of NoSQL such as Mongo or Cassandra.


This application will be low transactional...and will not be very large..thus the reason the company wants to use it to pilot...yet
at the same time I dont want to put that in as the requirement as its possible this is more a pilot for the company to think about one database going forward
versus having many different versions of Dbs in the enterprise.

Currently we have alot of SQL Server, Oracle, and DB2.  I also believe out external website is Maria.

So any thoughts?

I honestly hate just picking one only to say lets test it.  But that does seem to be the …
0
Hi. I have an ASP.net GridView that has several template columns like that shown below. A datatable is bound to the GridView
but sometimes one or two of the columns that the template fields bind to are not included in the datatable.
So if the "EmployeeName" column is not in the datatable  there will be an error. The only way that I can think of doing this
is to assign each datatable column to the corresponding gridview template column programatically but I am not sure how to do this

    <asp:TemplateField HeaderText="Employee Name" Visible="true">
                           <ItemTemplate>
                                <asp:Label ID="lblEmployeeName" runat="server" Text='<%# Bind("EmployeeName")%>' Visible="true"></asp:Label>
                           </ItemTemplate>
                      </asp:TemplateField>

Open in new window

0
Hi. I use the following code to in my ASP.net web app to allow the user to click a GridView cell that then loads the information
pertaining to that cell to other controls to allow editing. I would like to also make the editing possible in the gridview cell by turning
it into a text box. How would I do that? I cannot use Template columns and AutoGenerateColumns is true

   Private Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowCreated

        Dim dtNew As DataTable = TryCast(Session("dtNew"), DataTable)
        If e.Row.RowType = DataControlRowType.DataRow Then
            'Following link shows how cells are made clickable
            '//https://stackoverflow.com/questions/31202877/get-clicked-cell-index-in-gridview-not-datagridview-asp-net
            For i As Integer = 0 To e.Row.Cells.Count - 1
                Dim cell As TableCell = e.Row.Cells(i)
                cell.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.textDecoration='underline';"
                cell.Attributes("onmouseout") = "this.style.textDecoration='none';"
                cell.ToolTip = "You can click this cell"
                cell.Attributes("onclick") = String.Format("document.getElementById('{0}').value = {1}; {2}", SelectedGridCellIndex.ClientID, i, Page.ClientScript.GetPostBackClientHyperlink(CType(sender, GridView), String.Format("Select${0}", e.Row.RowIndex)))
            Next
        End If


    End Sub

    Protected

Open in new window

0
Hi

I'm trying to search a given directory for video and jpg files matching / renaming the jpg to the video
If a video file has a jpg with the same name I can skip it
else I want the user to choose from the list within the directory by typing the associated number or  a completely  new option / x (for no jpg)


in my test folder I have
File01.mp4
File02.mkv
File01.jpg
pic.jpg
SubFold
File01.jpg
File03.mp4
File03.mp4_snapshot_18.48_2019.06.03_19.50.59.jpg
File04.mp4
File04.jpg
File05.mp4
File garbish5.jpg

In the code bellow

First I'm not listing the top level directory only SubFold
Second how do I alow the users chose with the jpg file so I can rename it but filter out the jpg's  that already have a video
(Top folder don't show File01.jpg because of File01.mp4 SubFold Show File01.jpg, File03.mp4_snapshot_18.48_2019.06.03_19.50.59.jpg & File garbish5.jpg )
once the jpg has been rename this is no longer an option)

Some jpg files could be Auto renamed like "File03.mp4_snapshot_18.48_2019.06.03_19.50.59.jpg" but for now I just need to the manual choice


 
using System.IO;

namespace Kodi
{
    class Program
    {
        static void Main(string[] args)
        {
            string BaseFold = "";
            string Ans; 
            if(args == null)
            {
                Console.WriteLine("Drag a Folder to search");
                Ans = Console.ReadLine();
                BaseFold = Ans;
            }
            else
            {

Open in new window

0
using C# .net and LINQ to entities that is replacing embeded TSQL.  I may have two different where clauses to get data.  using embeded TSQL amd ADO
                        I could do something like this

                        
				String Search;
				String KeyToSearch;
				String sql ="":

				sql += "SELECT * ";
				sql += " FROM Accounts ";				
				sql += " WHERe ";			
				 if(KeyToSearch=="Key")
				 {
   				   sql += "AccountKey ='" + Search + "'";
				 } else

				 if(KeyToSearch=="Primary")
				{
   				   sql += " Id=" + Search;
				}				
				sql += " ORDER by  AccountName ";	
			
				Using(SQL CONNECTION.... ){
				.... execute sql
				.... Bind to whatever
				}
				
				with LINQ I can't do
		
				var filtered = (from c in db.Accounts
								if(KeyToSearch=="Key")
								{
								   where c.AccountKey == Search
								} 
								   else
								{
								   where c.Id == Search
								}								
								select c).ToList();
				.... Bind to whatever
				

Open in new window

                       How can I do this without creating two LINQ?
0
A while back I needed to add scroll wheel functionality to a panel. I am using this bit of code to capture and process the wheel messages and it works fine.
		public bool PreFilterMessage(ref Message m)
		{
			if (m.Msg == MSG.WM_MOUSEWHEEL)
			{
				if (recipientControl.Parent.ClientRectangle.Contains(recipientControl.PointToClient(System.Windows.Forms.Control.MousePosition)))
				{
					NativeMethods.SendMessage(recipientControl.Handle, m.Msg, m.WParam, m.LParam);
					return true;
				}
			}
			return false;
		}

Open in new window

There's just one problem, it processes the message even if another window is open on top of the main window. If I open another window using the ShowDialog() method it should block mousewheel handling for the panel in the underlying form. I just don't know how to detect whether or not a dialog is currently open. Can anyone help with this?
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.