.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,

Today I was asked this question:

We have
actualResult.AdditionalInfo[0].Content

Open in new window


Content itself have several properties such as Title, Type, Id, ActionPacks etc.
ActionPacks has 10 elements as
ActionPacks[0], ActionPacks[1], ActionPacks[2]....ActionPacks{9]

The question was
"how can we know the number of ActionPacks properties?

I answered like
actualResult.AdditionalInfo[0].Content.GetType().GetProperty("ActionPacks").Count

Open in new window

I know it's wrong.

Is there anyway I can find out the number of elements in ActionPacks?

Is this question even valid considering no additional information is given?
0
Hi,

I have set up a very simple update panel page as I was getting a full postback each time on a new site I have set up in VWD, it refuses to update just the update panel, but if I copy over the page to the older site it works fine.

They have identical web configs and I'm not using a master page so no interference there.

Same on the live server, one work, one doesn't - any ideas?

Cheers
Karl
0
Hi

I need to do some file management by creating a new directory for each film and associated files

the new Dir Name will be Film name Year

This information is stored in an SQLite  database which will need updating

In the code bellow I'm trying to pass the SQL query into a method and return a Movie Object I can then use this to create the New Dir etc
BTW The SQL Query is valid, admittedly there maybe a better way to do this however I'm running VS 2015   which doesn't have EF & EF doesn't play nice with SQLite  

I'm running into several errors
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0029	Cannot implicitly convert type 'string' to 'UpdateMoviePath.Program.MovieObj'	UpdateMoviePath	D:\Vb\Test\UpdateMoviePath\UpdateMoviePath\Program.cs	41	Active

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0161	'Program.RunQuery(string)': not all code paths return a value	UpdateMoviePath	D:\Vb\Test\UpdateMoviePath\UpdateMoviePath\Program.cs	52	Active

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0122	'Program.MovieObj.id' is inaccessible due to its protection level	UpdateMoviePath	D:\Vb\Test\UpdateMoviePath\UpdateMoviePath\Program.cs	85	Active

Open in new window


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using System.Configuration;
using System.Data.SQLite;

using System.Diagnostics;

Open in new window

0
Hi Experts,

We have an EDM in our c# app, and we use FileStream/FileTable technology to store documents (Word, PDF, etc.).  We have a database with only 2 filetable tables to make the job. (other data are stored in a second classical db).

One of our db in production was in "Recovery pending status" today, we see a lot of reasons and workaround to fix it.

For this time, we need to detach an reattach it, but it is not satisfactory for us, we want to know why and avoid this issue.

For information and for different reasons, our application needs to open an Office doc (word / excel) from c# and we use the Filetable share directory like \\serveur\instance\FS for that.
A strong constraint is that the user can open the document and save it transparently.

Our questions are:
1. At the moment where the db is in "Recovery pending status", are there any tools or SQL statement to help us to understand the reason?
2. Is there a daily check to be done regularly on the databases to prevent these issues?
3. Of course, this db contains about 50GB to 300GB and important documents, is there a risk of losing the data?
4. What are the usual tools to repair, for example: if we detach the db and we cannot reattach it, what to do?

Thanks a lot for your Help.

With kind regards
Herve
0
I am using VS2015 and VS2019. I often need to debug, step through, and compare code side by side in different branches.

So I need to have my projects have different ports.

I used to be able to do that in VS2012. How can it be done in VS2019.

I am using a web site, not a web application.

Thanks!
0
Try to create a razor pages in another new created folder "Pages". However, it seems that ASP.NET Core can't recognize it. Any idea ?

I'm using ASP.NET Core.

Thx
Eorro.png
Physical-Folder.png
0
Hi Experts!

Have a User class that implements IComparable<User>. What this gives us is the ability to sort on the list w/o having to create another list by FirstName.

    internal class User : IComparable<User>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }

        public int CompareTo(User other)
        {
            return this.FirstName.CompareTo(other.FirstName);
        }
    }

Open in new window


It looks users.Sort() works, but users.Reverse() doesn't work. Any ideas how to fix this?

Here's the entire code.
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject1
{
    internal class User : IComparable<User>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }

        public int CompareTo(User other)
        {
            return this.FirstName.CompareTo(other.FirstName);
        }
    }
    
    [TestClass]
    public class UnitTest1
    {
        List<User> users;

        [TestInitialize]
        public void StartUp()
        {
            users = new List<User>()
            {
                new User() {FirstName = "Sally", LastName = "Jones", Age = 30},
                new User() {FirstName = "Yu", LastName = "Lan", Age = 40},
                new User() {FirstName = "Sook", LastName = "Kim", Age = 20},
            

Open in new window

0
I'm interested in software freelancing part-time.  I am experienced embedded software engineer and I have some programming experience with .net C#.

Which is the best option for getting started?

  1. Look for freelance work in area of my experience.
  2. Learn some hot technology and look for freelance in this area.
0
Following on from an earlier question

I've created an Entity Framework MoviesDataModel now I'm struggling to work out how to use it I'm pretty sure it's to do with DbContext

I've created a console app in the same folder with the intention of just printing each movie title
Once I've done that I can then explore how to add a filter using LINQ something like

SELECT title from movie where person.name = 'John Wayne';

But first how do I connect and use the MoviesDataModel?

Writing the code bellow I had no intellisense nor does MovieTest appear in Solution Explorer


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using MoviesModel;

namespace MovieTest
{
    class Program
    {
        static void Main(string[] args)
        {
            List<MoviesDataModel.movie> movies = new List<MoviesDataModel.movie>();

            foreach (MoviesDataModel.movie movie in MoviesEntities)
            {
                Console.WriteLine(movie.title);
            }
        }
    }
}

Open in new window

0
I have the below c# code where I am trying to get a list of Message but I am getting the error below on the last line of the code
System.FormatException: 'Index (zero based) must be greater than or equal to zero and less than the size of the argument list.'

I am new to linq so I am sure I am missing something.  Any help would be appreciated .  thanks!

var query = from message in _messageRepository.GetMessage()
                    select new Message()
                    {
                        MessageCode = message.MessageCode,                        
                        Description = String.Format(message.FriendlyMessageText, value)
                    };
            return query.ToList();

Open in new window

0
We have an app running on IIS 8.5 which are KPI dashboards running SQL queries and displaying the results in a browser. We have an issue where the dashboards in general begin to slow down and eventually become useless. We have tested the SQL queries used in the dashboards directly against Oracle and they run fine with no delay. The only fix so far we have found is to run IISRESET. Once we run IISRESET, it begins to work again. We also test the same queries within our ERP system(Oracle backend) which the dashboards feed off from different PC's and they run fine. The issue is with IIS or the app itself. if it was the SQL query being too heavy, you would see a slow response time when ran directly in Oracle. we have gone through and set IIS to vendor and Microsoft recommendations including using recycling.

Aside from defects in the code of the app, Is there anything we are missing in IIS that may be causing the issue?
0
Hello,
Any suggestion on how to write a windows service to get data from URL and insert it into SQl table.

Regards
0
We have a Asp.net core restAPI hosted on windows Azure.
Now we are looking cloud based logging service which we can use for the api hosted on azure.

If any service are there please let us know.
0
Hi

I'm trying to work out how to Entity Framework

I've created a movie database in MS SQL and on to creating a MovieModel using Entity Data Model Wizard,and EF Designer from database,
The results are pictured bellow

how do I join the tables?
For instance

movie.id = movielinkperson.movieId
 movielinkperson.personId = person.id

I thought I could drag a line between the two this doesn't  work

MovieModel.JPG
0
Hi

I'm trying to find all the directories that contain an *.avi file so I can move the directory
Doesn't matter if other files type exist in the same directory

In the code bellow I'm finding every directory even with no avi

           string[] Dirs = Directory.GetDirectories(Root, "*", SearchOption.TopDirectoryOnly);
            foreach (string Dir in Dirs)
            {
                string NewDir = "";
                string[] Files = Directory.GetFiles(Dir, "*.avi", SearchOption.TopDirectoryOnly);

                // If a no avi file in Dir Files should not be  null  ??

                if (Files != null ) //|| Files.Count() >= 1)
                {
                    NewDir = avi_files + Dir;
                    string OldDir = Root + "\\" + Dir;
                    if (!Directory.Exists(NewDir))
                    {

                        //   Directory.Move(OldDir, NewDir);
                        Console.WriteLine("OldDir: {0} NewDir: {1} ", OldDir, NewDir);
                    }
                }
 
           }

Open in new window


The first Dir dose not have an *.avi file but in the "Immediate window"
Files != null
true

Open in new window

That means Files has an avi file ??

as you can see in the code i've tried different methods
var files = Directory.EnumerateFiles(Root, "*.*", SearchOption.AllDirectories)
                    .Where(s => s.EndsWith("*.AVI") || s.EndsWith("*.avi"));

Open in new window

0
By referring to:

https://jwt.io/#debugger-io

Untitled.jpg
I wish to implement the RS256 algorithm and get the Encoded Token in .NET

I managed to generate the encoded text for Header and Payload, using the following codes:

var header = new Dictionary<string, object>()
            {
                { "alg", "RS256" },
                { "typ", "JWT" }
            };
            String strHeader = Base64UrlEncode(JsonConvert.SerializeObject(header));

            var claims = new Dictionary<string, object>()
            {
                { "sub", "1234567890"},
                {"name", "John Doe"},
                {"admin", true},
                {"iat", 1516239022}
            };
            String strClaims = Base64UrlEncode(JsonConvert.SerializeObject(claims));

            textBox1.Text = strHeader + "." + strClaims;

Open in new window


private String Base64UrlEncode(String input)
        {
            var inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
            // Special "url-safe" base64 encode.
            return Convert.ToBase64String(inputBytes)
              .Replace('+', '-')
              .Replace('/', '_')
              .Replace("=", "");
        }

Open in new window


But I got problem in generating the Signature part?

Appreciate the assistance here, thanks.
0
Hi,
How to prevent xml external entity (xxe)  through C#

StringReader a= new StringReader(b);
a= new XmlTextReader(a);
reader.XmlResolver = null
 <<<<<<Security tool is reporting here that possible of XXE mitigation>>>>>>>>>>>>>>>>
 
i applied
StringReader a= new StringReader(b);
a= new XmlTextReader(a);
a.XmlResolver = null;
a.DtdProcessing = DtdProcessing.Prohibit;
bool b = a.Read();

am not getting any value in a.
0
Hi

The object of my exercise is to learn Entity Framework most of the time I will have created a Database already

I'm using Visual Studio 2019 the tutorials I've found are based on 2017

I've given up trying to connect to an SQLite database as steps  outlined here suggest SQLite isn't compatible with VS 2019


So I  dumped the Database to an SQL file this has both table structure  and data but no database creation

Can someone tell me how to create a Microsoft Server Database and import this SQL file

I then would like to know how to create a DB connection class s  I can use it in different applications
0
VB .net creating mailitem via Microsoft.Office.Interop works for me but not others ??

They get the error...
System.BadImageFormatException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

I've already tried Target x86 in the compile options with no luck.
I've tried 2 ways of adding the Reference....

1. Add Reference/COM
2. Add via Nuget PM > Install-Package Microsoft.Office.Interop.Outlook -Version 15.0.4797.1003 (with Embed Interop Types = True)

All variations work on my machine (64 bit Win10 Administrator accounts) but not others (also 64 bit Win10 Administrator accounts)

When adding reference via COM and i check the properties i have an Identity = {00062FFF-0000-0000-C000-000000000046}\9.6\0\primary so I'm also wondering if this is a clue as the error is reported on 0006F03A-0000-0000-C000-000000000046 ??

All help appreciated
0
I'm trying to populate a list box and I keep getting the following error.

This is the error!

Here is my code:
     private static void DirectoryCopy(string sDir, string dDir, bool copySubDirs)
        {
            Cursor.Current = Cursors.WaitCursor;

            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sDir);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sDir);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();

            // If the destination directory doesn't exist, create it.
            if (!Directory.Exists(dDir))
            {
                Directory.CreateDirectory(dDir);
            }

            // Get the file info for each file in the in the directory
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string dst = Path.Combine(dDir, file.Name);
                string src = Path.Combine(sDir, file.Name);

                //Display which file is currently being worked on
                ChangeLabelText(file.Name);

                //use the SafeCopy() function to copy each file until it finishes before copying the next file.
                SafeCopy(src, dst, 10000);

                //add the name of the file that was just copied to the 

Open in new window

1
Need to create a Mac Based Image Library

I have thousands of photos of all sorts, and need to build an automated search where I can add attributes and pull up images which satisfy my search criteria.

These are not modern photo's of people, so face recognition is not relevant. Photos are of buildings, maps, historical details, and a few faces, but even those are not usually photographs and tend to be paintings.  So, no face rec.

Also, these are my own private images and do not warrant a cloud solution. Privacy and being able to protect my datas is more important to me. BUT, I would consider using an Azure solution, IF I also had total access to my images with no Internet connection. (I do want some exposure to Azure, as a .NET Developer)

What tools exist that are configurable for this?

I need to add as many attributes as I would like. I need the search tool to reconfigure to include a new attribute.

I am a .NET Software Engineer, so a bit of coding would not scare me.

I would not be afraid to use a cloud solution IF I could also be able to ensure I have the ability to run it locally on my MacBook. My images are controversial, and could cause the master of the universe to try and cut my account...

What about a WordPress plug-in? I would host WP on my Mac if required for this.

I am trying to find a tool (or tools) I can use that will save me a world of work.

Thanks.
0
Hi,

I am working on .net using c#

I am posting data in method PostAsJsonAsync using package System.Net.Http.

Please advise me with my findings.

I am getting  response as

ReasonPhrase = "Unauthorized" string
StatusCode = "BadRequest" System.Net.HttpStatusCode

Not sure but looks to me that url(https://edg-dev-sit.dfdegg.net/loyalty/identity/v2/ssotoken) where I am submitting the data is not allowing data to be submitted from myside.

or Allow origin is not done.

I am not sure. Please help me with my finding.

My code is
HttpResponseMessage response = mHttpClient.PostAsJsonAsync<T>(uri.ToString(), data).Result;

where 
uri.ToString() is https://edg-dev-sit.dfdegg.net/loyalty/identity/v2/ssotoken

and data is { grantType = "authorization_code", authorizationCode = "umKTS4bKXOedNSjuv2rq" }

Open in new window



mHttpClient is as follows:

System.Net.Http
private HttpClient mHttpClient = null;

mHttpClient = new HttpClient(httpClientHandler)
            {
                Timeout = timeout,
                DefaultRequestHeaders =
                {
                    AcceptEncoding =
                    {
                        StringWithQualityHeaderValue.Parse("gzip"),
                        StringWithQualityHeaderValue.Parse("deflate")
                    },
                    CacheControl = new CacheControlHeaderValue() { NoCache = true }
                }
            };

Open in new window


My response (HttpResponseMessage response) is as follows.
See screenshot attached.


Open in new window

0
I have created a new SQL database with all the required data and tables. The DB houses PDF's and other data. Using SSMS i can run query's and pull the data I need but it's not good for the staff.

What I want to do is to created maybe a simple web page (think google search) or front end where they can type in a key word, phrase, or combination of both and get a result list with a download option for the pdf/documents if any.

How would I start on creating such a front end? I have never made any front end's for SQL DB before
0
Hi
I'm using MS Visual Studio 2019!

working through 20483-Programming-in-C-Sharp training course I'm at Module 7: Accessing a Database
and looking at the demo from here

@step 9 "Add New Item – FourthCoffee.Employees dialog box click ADO.NET Entity Data Model, "  I don't see this  searching "ADO" or "Entity" finds ZERO

I thought I might need a Nuget package   so Search for ADO and installed EntityFramework 6.2.0  resulting in Errors

Severity      Code      Description      Project      File      Line      Suppression State
Message      IDE0060      Remove unused parameter 'args'      FourthCoffee.Employees      E:\VB\20483-Programming-in-C-Sharp-master\Allfiles\Mod07\Democode\Demo1\Starter\FourthCoffee.Employees\FourthCoffee.Employees\Program.cs      7      Active
AND

Severity      Code      Description      Project      File      Line      Suppression State
Warning      NU1701      Package 'EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.      FourthCoffee.Employees      E:\VB\20483-Programming-in-C-Sharp-master\Allfiles\Mod07\Democode\Demo1\Starter\FourthCoffee.Employees\FourthCoffee.Employees\FourthCoffee.Employees.csproj      1      

Any suggestion where to find ADO.NET Entity Data Model as I can't proceed to the course exercise as this is doing similar

BTW: If you attempt this @  1 copy the FourthCoffee.sql file to "C:\Users\User.Name" before running SetupFourthCoffeeDB.cmd.
0
I have this code that works for joining a computer to a group, but occasionally fails to join. This does a search for the group, but I don't need to search, I know the exact name of the group and where it's located.  The user is adding the computer into the domain and then into groups using ldap credentials. This code searches for the group, but I have the name and location of the group so I want to avoid searching.


    Private Sub ComputerGroupAdd(ByVal GroupName As String, ByVal ComputerName As String)
        Try
            Dim sDomainName As String = "LDAP://mydomain.local"
            Dim adUserFolder As DirectoryEntry = New DirectoryEntry("LDAP://mydomain.local/DC=mydomain,DC=local")

            adUserFolder.Username = "mydomain.local\myUser"
            adUserFolder.Password = "mypassword"
            Dim adSearch As New System.DirectoryServices.DirectorySearcher(adUserFolder)

            adSearch.Filter = String.Format("(&(objectCategory=group)(sAMAccountName= {0}))", GroupName)

            For Each x As SearchResult In adSearch.FindAll
                Dim group As DirectoryEntry = x.GetDirectoryEntry
                group.Properties("member").Add(ComputerName)
                group.CommitChanges()
            Next
        Catch ex As Exception
                MsgBox(ex.Message)
        End Try
    End Sub

Open in new window

How can I add a computer to a group with credentials using the group's exact name and location. In other words, without searching for the group, which is what this code is doing. 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.