.NET Programming

133K

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
Following on from here

Within
......
 string[] Files = Directory.GetFiles(folder);
foreach (string file in Files)
 {
   FileInfo FI = new FileInfo(file);  // exception  raised 
   // Do Stuff with FI
 }

Open in new window


if the file is a *.url  / shortcut to web page I get a "PathTooLongException " I haven't seen it with other files and it doesn't happen every time

I'm 100% sure  The length of the path dose not exceed Int16.MaxValue (32,767) characters.

So how do I handle this exception

I tried something like this but the exception is still raised

......
 string[] Files = Directory.GetFiles(folder);
foreach (string file in Files)
 {
   try
     {
      FileInfo FI = new FileInfo(file);  // exception  is still raised 
      // Do Stuff with FI
     }
   catch
     {
       //Do nothing
          continue; 
     }
 }

Open in new window

0
Cloud Class® Course: CompTIA Healthcare IT Tech
LVL 12
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

I have an asp.net project . I want to version the JavaScript files, when there are any new changes to those files , so that browser downloads the latest .

Are there any tools/ nuget packages for this ?
0
When user send reply email , to specific email address, i need to update the Database value "yes"
if user reply  user reply.
0
I have a question regarding validation of fields provided from a WCF web service.

Let's say that the web service has 6 fields:

MemberFirstName
MemberLastName
MemberNumber
AptType
City
Referral


Now, I want to check that when a Referral is provided the MemberFirtName *and* MemberLastName are also provided. When a City is provided the AptType *or* a MemberLastName is provided.

What is the best way to achieve something like that?


This is in C# with VS 2015.

Any information would be greatly appreciated.
0
Hi,

I am practicing some algorithm to merge 2 existing arrays.
Here are the requirements I created:
1. no Linq allowed.
2. no concat, copyTo. Array.Sort() method allowed.
3. result should be sorted by ascending order.

I actually completed the coding, but there must be much better solution.
I also had to create Sort method to sort the result array.
Is there anyway I can sort while merging?

Currently I am Merging and then Sorting.


 
static void Main(string[] args)
        {

            int[] a = { 1, 2, 3 };
            int[] b = { 1, 2, 3 };

            int[] result = Sort(MergeTwoArrays(a, b));
            foreach (var item in result)
            {
                Console.Write(item+ " ");
            }           

            Console.Read();
        }

        public static int[] MergeTwoArrays(int[] a, int[]b)
        {
            int aLength = a.Length;
            int bLength = b.Length;
            int totalLength = aLength + bLength;
            int[] c = new int[totalLength];

            for (int i = 0; i < a.Length; i++)
            {
                c[i] = a[i];
            }
            int k = a.Length;
            for (int i = 0; i < b.Length; i++)
            {
                c[k] = b[i];
                k++;
            }
            return c;
        }

        public static int[] Sort(int[] a)
        {
            int i, j, temp, minIndex;
            for (i = 0; i < a.Length; i++)
            {
                minIndex = i;
    

Open in new window

0
Hi,

 I am still getting
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

To add more information :
 If there are column names at the end of  the excel sheet , and there is no data in that column (cell) it comes with the blank with ','
Basically it should detect that there is no data after this column and stop adding the comma (,,,,)


How can I avoid this at the end of the column with used range.


The code I am using in vb.net is :

        Dim officeType As Type = 

Open in new window

0
I have a View that is the Success Page of a Form submit.  It contains a DataTable:

<div id="data">
    @Html.Table(master.Models.HTML.HtmlTable.Table.WorkOrder_ViewWorkOrders)
</div>

Open in new window


The Controller for this View is:

[HttpPost]
public JsonResult Success(int id)
{
    List<string[]> tableData = new List<string[]>();
    List<string> row = new List<string>();

    List<Success> Orders = (from x in DB.vw_Success
                                            select x).ToList();
    Orders = (from x in Orders
                    where x.ID == id
                    select x).ToList();

    for (int i = 0; i < Orders.Count(); i++)
    {
        row.Add(Orders[i].Name);
        row.Add(Orders[i].LOCATION);
        row.Add(workOrders[i].Item);

        tableData.Add(row.ToArray());
        row.Clear();
    }

    return Json(new { data = tableData });
}

Open in new window


I need to add a partial view to my Success View to show additional details about the Order at the top.
I believe I add it by adding this to the View:      @Html.Partial("~/path to my view.../Details.cshtml");

The Controller for the Details View is:

 
[HttpPost]
public ActionResult Details(int id)
{

    List<vw_Success> Orders = (from x in DB.vw_Success
                                            select x).ToList();
    Orders = (from x in Orders
                    where x.ID == id
                    select x).ToList();

    return View(Orders.OrderByDescending(x => x.ID).ToList());
}

Open in new window


A snippet of my Partial View for Details is:

@model List<master.Areas.Order.Models.vw_Success>

<div class="panel panel-info">

    <div class="panel-heading">Order Details</div>

    <div class="panel-body">

        @for (int i = 0; i < Model.Count; i++)
        {
            <div class="row" style="margin-bottom: 10px;">
                <div class="col-xs-8">
                    <span style="font-weight: bold;">Order Name: @Model[i].Name</span>
                </div>

                <div class="col-xs-4">
                    <span style="font-weight: bold;">Part #:</span>
                </div>
            </div>

Open in new window


The View contains much more but that is enough to explain my problem.
The Model is not returning anything.  I believe I need to pass the id parameter to the partial view somehow.

Thank You!
0
I have a .net solution, with few projects. one of them is web site which is an angular project with an asp.net web api project as a backend.

when I compile the solution or when i try to build just the asp.net website , i get the following error. I have looked through the csproj file for all the projects , but can't find reference
to the following in any projects.

I googled it but didn't find anything helpful yet.

has anybody run into similar issue?

The CodeDom provider type "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.
0
I'm able to pass the query parameter successfully to the field however when the item is saved the record is not being saved to the list. What's interesting is that if I manually override the passed value by typing into the field on the form and then clicking save, the record is saved to the list .

We have a working example of this on the same site for a different list that we created about a year ago and does not have this issue.


Original Code Provided when a new form was created for the list in SPD:
<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="New" FieldName="AttachmentsID" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@AttachmentsID')}"/>
<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="AttachmentsID" ControlMode="New"/>


Removed the above code and replaced with the following:                                                            
<asp:TextBox runat="server" id="ff1{$Pos}" Name="FileName" Text="{$AttachmentsID}" Value="{@AttachmentsID}" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@AttachmentsID')}" Width="100px" Height="20px" BorderWidth="0" />
0
using System;

public class RemoveRepetitions
{
    public static string Transform(string input)
    {
        throw new NotImplementedException("Waiting to be implemented.");
    }

    public static void Main(string[] args)
    {
        Console.WriteLine(RemoveRepetitions.Transform("abbcbbb"));
    }
}
0
Cloud Class® Course: SQL Server Core 2016
LVL 12
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

How to maintain " double quotes to a string in C#.I  have multiple combination of passwords with " double Quotes.

Example: I have password =>ABC"DEF and "XY"Z" and p"ass"/"rdc

Refer->
In this screen i have seen only ABCDEF but not able to see ".
0
I have hundreds of classes that implement the IDataReader. Ultimately I would like to be able to override the GetDateTime() so I can covert all the dates coming back from SQL in UTC to local. I know you cannot inherit the SqlDataReader class but the GetDateTime() is overidable. Is there any way that this can be done?

I have an extension method but that would require so append to thousands of lines of code rather then Having an ExtendedDataReader class that somehow inherits the IDataReader and overrides the GetDateTime so I can just replace "IDataReader" with DataReaderExtended".

Please let me know if you have any questions.
0
I've been tasked to write an app that gets data from MS Excel.  I wrote below and have modified it a bit for the different spreadsheets.  Because of this I thought of making it Generic.

Issue I have is that the Model could contain 1 field or 2 fields, etc.  

Is there a way to write this so it is generic?
    public interface IExcelReader<T>
    {
        List<T> GetExcelData(string filename, string worksheet, string rowstart, string rowend);
    }

    public class ExcelParser<T> : IExcelReader<T> where T : new()
    {
        private Microsoft.Office.Interop.Excel.Workbook _excelbook = null;
        private Microsoft.Office.Interop.Excel.Application _excelapp = null;
        private Microsoft.Office.Interop.Excel.Worksheet _excelsheet = null;

        private string _worksheet = string.Empty;
        private string _filename = string.Empty;
        private string _path = string.Empty;
        private string _rowstart = string.Empty;
        private string _rowend = string.Empty;

        List<T> result = new List<T>();

        private List<ComponetsFullModel> _manufpartno = new List<ComponetsFullModel>();

        public List<T> GetExcelData(string filename, string worksheet, string rowstart, string rowend)
        {
            _worksheet = worksheet;

            Uri uri = new Uri(filename);
            if (uri.IsFile)
            {
                _filename = System.IO.Path.GetFileName(uri.LocalPath);
                _path = 

Open in new window

0
Hello,
Excel Sheet import changes the format of the column.
I am importing a excel sheet in to grid , the format of the date field is set automatically to Datetime.
Please find the code below.
The requirement is that it treats the column as a text column.

Example:
Dates in the column are 18/06 - 23/06 . When I  import the excel sheet , the cell is blank.

 Private Sub PopulateExcelInDatagrid(ByVal Filename As String)
        Dim oledbCon As OleDb.OleDbConnection
        Dim dt As New DataTable
        Try
            Dim csExcel As String = ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & Filename & " '; " & "Extended Properties=Excel 8.0;")
            oledbCon = New OleDbConnection(csExcel)
            oledbCon.Open()
            dt = oledbCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
            oledbCon.Close()
            If dt.Rows.Count <= 0 Then Exit Sub
            Dim excelSheets As [String]() = New [String](dt.Rows.Count - 1) {}
            Dim row As DataRow = dt.Rows(0)
            oledbCon.Open()
            Dim oledbAdapter As New OleDbDataAdapter("select * from [" + row("TABLE_NAME").ToString() + "]", oledbCon)
            oledbCon.Close()
            Dim excelDataSet As New DataSet()
            oledbAdapter.Fill(excelDataSet, "Test")
            Dim excelTable As DataTable = excelDataSet.Tables("Test")
            Dgv.DataSource = excelTable
            With Dgv
                .MasterTemplate.BestFitColumns()
          

Open in new window

0
I have a python file with several variables declared right at the beginning of the code. I then have a few small classes declared (in-line inside of the same file) and finally a large loop with all the logic. What I've noticed is that at the end of the outer loop I zero-out the variable and begin again (note: the zeroing-out does work...I can see it in the debugger). The strange thing is that as soon as the loop starts again, the variables revert back to what they were when the loop completed (as if the zeroing...initializing...never happened).

I am stepping through line by line.

What am I not understanding here? Does python just deal with scope differently than other languages?

import statements
variables

class declared
class declared

outer loop:
  .
  .
  inner loop:
     .
     .
  reset variables

Open in new window

0
Would like to merge multiple files of varying file types into one PDF.  These files are being uploaded to an Amazon S3 bucket.  Need a way to just select the files I need via a web interface on my website and output the files into 1 PDF.  Is there code or scripts anyone can recommend to accomplish this task?  Some file type examples needing to be merged into 1 PDF would be JPEG, PNG, and PDF.

Code I am working in is basic .NET C#

Any help / advice would be greatly appreciated.   Thanks!
0
In C#, I have a list of object and want to concatenate its nested object property value by another property of the same value. These the classes and example:
public class Grn
    {
        public string referenceNumber { get; set; }
        public List<GrnLine> grn_line { get; set; }
    }

public class GrnLine
    {
        public string productCode { get; set; }
        public string serialNumber { get; set; }
    }


List<Grn> grnList1 = new List<Grn>() {
                    new Grn { referenceNumber = "ref1", grn_line = new List<GrnLine> {
                        new GrnLine { productCode = "productA", serialNumber="A1" },
                        new GrnLine { productCode = "productA", serialNumber="A2" },
                        new GrnLine { productCode = "productB", serialNumber="B1" }
                    } },
                    new Grn { referenceNumber = "ref2", grn_line = new List<GrnLine> {
                        new GrnLine { productCode = "productC", serialNumber="C1" },
                        new GrnLine { productCode = "productD", serialNumber="D1" },
                        new GrnLine { productCode = "productD", serialNumber="D2" }
                    } }
                };

Open in new window


How to concatenate each serialNumber into a new line of GrnLine object having the same productCode? So it will be something like:
List<Grn> grnList2 = new List<Grn>() {
                    new Grn { referenceNumber = "ref1", grn_line = new List<GrnLine> {
                        new GrnLine { productCode = "productA", serialNumber="A1" + Environment.NewLine
                                                                            + "A2"},
                        new GrnLine { productCode = "productB", serialNumber="B1" }
                    } },
                    new Grn { referenceNumber = "ref2", grn_line = new List<GrnLine> {
                        new GrnLine { productCode = "productC", serialNumber="C1" },
                        new GrnLine { productCode = "productD", serialNumber="D1" + Environment.NewLine
                                                                            + "D2"},
                    } }
                };

Open in new window

0
OS Version = 6.1.7601, SP = 1.0, Platform 2, Service Pack 1
 OS Description = Win7 - x86 Ultimate Edition Service Pack 1

MSI = 5.0.7601.24052
 Windows version = x86_windowsfoundation_31bf3856ad364e35_6.1.7601.17514_none_0541445eeedbd616.manifest
 Windows servicing = 6.1.7601.23505

CommandLine = C:\9ee15b01a210fac5903df85169c556\\Setup.exe /x86 /x64 /redist
 TimeZone = ??????, ?????? (????)
 Initial LCID = 1049
 Using Simultaneous Download and Install mechanism

Operation: Installing

Package Name = Microsoft .NET Framework 4.7.2 Setup
 Package Version = 4.7.03081

User Experience Data Collection Policy: AlwaysUploaded

Number of applicable items: 10
 Exe (C:\9ee15b01a210fac5903df85169c556\SetupUtility.exe) succeeded.
 Exe Log File: dd_SetupUtility.txt

ServiceControl operation succeeded!

ServiceControl operation succeeded!
 Exe (C:\9ee15b01a210fac5903df85169c556\SetupUtility.exe) succeeded.
 Exe Log File: dd_SetupUtility.txt
 MSI (C:\9ee15b01a210fac5903df85169c556\netfx_Full_x86.msi) Installation failed. Msi Log: Microsoft .NET Framework 4.7.2 Setup_20180731_093830339-MSI_netfx_Full_x86.msi.txt
 Final Result: Installation failed with error code: (0x80070643), "В процессе установки произошла неисправимая ошибка. " (Elapsed time: 0 00:08:47).

Open in new window

0
I have winforms project with databound textbox. It's bound to the datetime column in the dataset, and I have specified non-empty NullValue for the dataset column.

The dataset gets filled from sql server database, and the date column is indeed NULL. Accordingly, I expect to see my specified value in the textbox on the form. But instead I see empty string. Why?

I attached a sample project.

WindowsFormsApp1.zip
0
Cloud Class® Course: Ruby Fundamentals
LVL 12
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Hi, I am new to ASP.net programming. Fyi, I am trying to read title data(xml data) from my response query string(working), however, I couldn't retrieve any data from my code.

protected void Update_btn_click(object sender, EventArgs e)
        {
            String new_title = newtitle.Text.ToString();
            String new_description = update_des.Value.ToString();
            String postid = Request.QueryString["pid"];
            
                        

            string filename = "C:\\Users\\user\\Source\\Repos\\FoodBlog\\FoodBlog\\Data\\blog_post.xml";
            XmlDocument xml_doc = new XmlDocument();
            XmlNode elemList = xml_doc.SelectSingleNode("/Posts/Post[@pid=" + postid + "]");
            String test = elemList.ChildNodes[0].Innertext;
            System.Diagnostics.Debug.WriteLine(test);
}

Open in new window


My XML data :
<Posts)
<post pid="pid2623">
    <title>Test</title>
    <description>Test</description>
    <subtitle>Test</subtitle>
    <date>7/29/2018 12:00:00 AM</date>
    <author>est</author>
  </post>
</Posts>

Open in new window

0
Hello,

I need to create a program that can send request to amazon S3 to download particular files. files should be ZIP (Archive) and start download.

I am using .Net for this solution

Any help much appreciated.

Regards.
0
I need to using a column of check boxes in gridview select and then download the files that are checked
I need to let the user select a download folder and the Filepload control is not letting me select a path only
0
Hi Experts,

i have to add some custom code to SAP gui scripting code, we have customized code like the script read the data from the excel.
but we want to add more customization in the code.

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

Dim cnnExcel, rstExcel
Dim strExcelFile
strExcelFile = "C:\Users\kt5775\Desktop\Engie work\SAP info\Tcodes input.xlsx"

Set cnnExcel = CreateObject("ADODB.Connection")
    cnnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=" & strExcelFile & ";" & _
               "Extended Properties=""Excel 8.0;HDR=NO;"""

    Set rstExcel = CreateObject("ADODB.Recordset")
    rstExcel.Open "Select * from [Sheet1$A1:G1000]", cnnExcel, adOpenStatic

session.findById("wnd[0]").maximize
Do Until rstExcel.EOF or UCASE(rstExcel.Fields(0).Value) = "LAST"


session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/npfcg"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtAGR_NAME_NEU").text = rstExcel.Fields(0).Value
session.findById("wnd[0]/usr/btn%#AUTOTEXT003").press
0
Hello everyone! I hope you are all doing well.  I've been looking at a few Single Sign on services provider. Centrify and Azure to name a few. Any other reliable and easy to setup Single Sign on services with excellent support? I have to add about 12 different cloud apps and wanted to make sure I can find one that perhaps will support us through the implementation process since some of the apps are not common.
0
Hello,

I have a website in IIS 8.5 and I have 2 domains pointed to the site domain.com and domain.net using the site bindings. Everything was working fine until 2 days ago when the domain.com started to give me Error:

404 - File or directory not found.

The domain.net works perfectly and it is weird because the error just happens on Chrome or Firefox on multiple machines. Edge works fine and also Android devices show the correct page.

I cleaned cookies and cache on both browsers, confirm that IIS has the correct Application pool for .net 2.0 classic mode, that the default document is listed in IIS and nothing works. If I add the default website to web.config the website doesn't load because it is inheriting the default website from parent. What could be the problem? Any help will be appreciate it.

Thanks
0

.NET Programming

133K

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.