C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

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

Sign up to Post

I am writing unit test case for my asp.net application . I am newbie in unit testing. I have following doubts. Could you please clarify the below doubts:

1. I have written unit test for all methods in my application which include privite, protected, public , function returns void,int,list so on.. is that necessary?
2. I felt some of the functions like page_load and button_click , does this need to write unit test cases?  
3. How i will write unit test for void methods? do i just need to check the function will not throw an exception.
4. Suppose a function is returns SQL queries as string, how i should i write test case , i just need to check the function will not throw an exception?
5. Suppose , if we are writting unit test for all function in application it wil effect the code coverage right?
0
Well here's my code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Networking;
using Windows.Networking.Sockets;
using Windows.Storage;
using Windows.Storage.Streams;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace Bluetooth_4_
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        StreamSocket outputsocket = new Windows.Networking.Sockets.StreamSocket();

        StreamSocket inputsocket = new StreamSocket();

        StreamSocketListener connectionlistener = new StreamSocketListener();

        List<string> stringlist = new List<string>();

        List<StreamSocket> connectedsockets = new List<StreamSocket>();

        Dictionary<string, StreamSocket> v = new Dictionary<string, StreamSocket>();

        EndpointPair p = null;

        DataReader r = null;

        StorageFolder fol = null;

        public MainPage()
        {
            this.InitializeComponent();

            

Open in new window

0
In VS 2017 I have a WinForms app which incorporates a couple DLLs. When I run the app from VS (debug or release) it works just fine. However, when I then attempt to run the EXE from the Bin/Release or Bin/Debug mode, it fails (Windows message says "[app name] has stopped working (Windows is checking for a solution to the problem)". The little progress bar pulses for a few seconds then the dialog disappears (typical behavior for that message).

Some background:
I had to change one of the DLLs to compile as x86 so that it would work with Windows 10 (and that change got me to the point where the app would launch in VS just fine). The DLL leverages an old api so I have to keep the framework of the DLL at 2.0. Note also that the consuming application is compiling just fine at framework 2.0; so, I think that the framework compatibility is all good.

Anyway, those are the only changes I've made, and VS seems happy with it, but Windows chokes on the EXE (Windows log shows a Kernelbase.dll error).

Thanks in advance for the help.
0
My DB design:
resolve Table: id, resolve
Resolve_system: id, resolve_id, system_id, is_active
Results table: id, feedback_id, system_id, resolve_id

On page load, it will display all the feedbacks in the gridview. Clicking on the feedbackid in gridview row will open the details in the formview.

Some of the items in resolve table are inactive now. But there are many old records which have inactive resolve. I want old records have the old inactive value selected in the dropdownlist, but for new items, it will display only active values in the resolve dropdown.

        <asp:FormView ID="fvRecordDetail" runat="server" DefaultMode="Edit" Width="100%">
                                                    <EditItemTemplate>
                   <asp:DropDownList ID="ddlResolveRD" runat="server"  AppendDataBoundItems="true" DataSourceID="sdsResolve" DataTextField="resolve" DataValueField="id" SelectedValue='<%# Eval("resolve_id") %>' Width="100%"  >
                                                                                    </asp:DropDownList>
                                                                                    <asp:HiddenField ID="hidOrgResolveSelectedValue" runat="server" Value='<%# Eval("resolve_id") %>' />
                                                                                            
   <asp:SqlDataSource ID="sdsResolve" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnString %>"
            

Open in new window

0
Hi,

I have one dropdownlist. On page load, it will display the FormView EditItemtemplate the already selected value. The already selected value comes from the old list. Old list items are some retired. If status is closed, display this
otherwise display all active in dropdownlist.

   <asp:TableRow>
                                                                                <asp:TableCell HorizontalAlign="Left" VerticalAlign="Middle" Width="110px">
                                                                                    <asp:Label ID="lblResolutionRD" runat="server" CssClass="Label" Text="Resolution:" />
                                                                                </asp:TableCell>
                                                                                <asp:TableCell HorizontalAlign="Left" VerticalAlign="Middle" Width="250px">
                                                                                    <asp:DropDownList ID="ddlResolutionRD" runat="server" CssClass="CriteriaField" DataSourceID="sdsResolutions" DataTextField="resolution" DataValueField="id" SelectedValue='<%# Eval("resolution_id") %>' Width="100%" >
                                                                                    </asp:DropDownList>
                                                                                    <asp:HiddenField ID="hidOrgResolutionSelectedValue" runat="server" Value='<%# Eval("resolution_id") %>' />
          …
0
Hi Experts,
I need help displaying a .pdf document from a button in my mvc.net application with C# code-behind.
I am using a Kendo UI grid to display some records.  One of the columns in the grid displays the values in button format.

When the user clicks on one of the buttons (which looks like a link).  I want to open a .pdf file located in the following directory:
C:\MyPDFs\

NOTE: The value displayed on the button is also the name of the .pdf file

I need to write a javascript function to display the file.  The function will take one parameter (the field value displayed on the button).
How do I write my javascript function?

Here the code I have for my Kendo UI grid:

{
field: "ND",
title: "ND",
template: "&nbsp;<input type='button' value='#=kendo.toString(ND)#' onclick='DisplayRejectFiles('#=kendo.toString(ND)#') class='RoundCorner'' style='width: 150px;border:0; background-color:Pink; color:blue;' />",
},

Open in new window

0
how to create dynamic column name while converting ilist to excel based on the field values in the list
0
i have emailed a html document as MS word document in attachment in c# code. So while opening the attahment in my local machine it is opening in MS word 2010(installed in my local). earlier we used to open it in MS word 2003 .So in 2010 ,the margins of the page are getting changed . how can i fx the margins of the page as Microsoft office 2003 default margins (1.25 inches right and left)? so that everytime the attachment is opened in any version of Microsoft word ,the margins remain same.
Also ,if i open the same document in 2003 ,the margins are correct(right and left 1.25") while opening in 2010 the margins are getting changed to 2010 default margins(right and left 1")   .I want it to be 1.25" in 2010 also.

if i open in 2003 and save it then if i open the saved doc in 2010 then the margin is coming as default 2003 margin. Soi want to do this by code.
0
getting below error message while loading the site.

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

Parser Error Message:
config section 'system.web/compilation' already defined
Sections must only appear once per config file.  See the help topic <location> for exceptions.

Please help me to resolve this.
Web.config
0
I have an installshield program that works fine in terms of saving local files, data files registration information but with previous installations of the product (not controlled by Install shield)  those files are deleted during the reinstall
0
I had this question after viewing asp.net repeater modal & data command.
0
hi want combobox in datagrid and do crud operation in wpf with EF.
0
I have an application that has been written for me and i have all the source code.  When i compile and run it i get the following error.  What can be causing this?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.ToolStripMenuItem' to type 'System.Windows.Forms.Control'.
   at Accusoft.FSInvoicesDemo.MDIParent2.localFolderToolStripMenuItem_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: …
0
hi,

I have gridview. chexbox is inside gridview. its giving an error when there is no data . Checkbox ix a bit field. How to resolve it.

  <asp:TemplateField HeaderText="Status"  HeaderStyle-HorizontalAlign="Left"   >
             <ItemTemplate>
                  <asp:CheckBox ID="lbIsActive" Enabled="false" runat="server"  Text="" Checked='<%# Eval("IsActive") == DBNull.Value ? false :  Eval("IsActive") %>' /> Is Active?
             </ItemTemplate>
             <EditItemTemplate>
                 <asp:CheckBox ID="rdIsActive" runat="server" Text="" Checked='<%# Eval("IsActive") == DBNull.Value ? false :  Eval("IsActive") %>'/> Is Active?
             </EditItemTemplate>
            <FooterTemplate>
                 <asp:CheckBox ID="inIsActive"  runat="server"  /> Is Active?
        
            </FooterTemplate>
         </asp:TemplateField>


c#
   protected void Page_Load(object sender, EventArgs e)
    { 
            if (!IsPostBack)
            {
                LoadAllApplications();
            }
}

   protected void LoadAllApplications()
    {
        try
        {
            AppAccessDataLayer obj = new AppAccessDataLayer();
            DataSet ds = obj.GetAllApplications();

            int count = ds.Tables[0].Rows.Count;
            if (ds.Tables[0].Rows.Count > 0)
            {
                gridView.DataSource = ds;
                gridView.DataBind();
            }
            else
            {
                

Open in new window

0
Hi Experts,
I have an MVC.Net application that uses C#.Net code behind.
In my views I use a Kendo UI grid.  One of the columns in the grid is a link.

When the user clicks on the link it should open a .pdf file.  So we need to pass the file path and the file name.
How can I do this?

Thank you,
mrotor
0
good day,
i am using window form app
i would like to adjust my graph while clicking on the track bar. how can i do that, please i need assistance
i have attached 2 files , please take a look at it.
this is the code for my track bar click event, it is not working
 private void trackBar1_Scroll(object sender, EventArgs e)
        {
            if(trackBar1.Value == 1)
            {
                // the updatePoint is the method i used to get the highest point and incremented the highest by 1
                updatePoint();

                // this is for drawing the graph after the change has been made
                drawGraph();
            }
        }

Open in new window



Open in new window

adjust0.png
adjust1.png
0
Hello I have an error in my code


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UCS.Core;
using UCS.Core.Network;
using UCS.Core.Threading;
using UCS.Helpers.Binary;
using UCS.Logic;
using UCS.Packets.Messages.Server;

namespace UCS.Packets.Messages.Client
{
    // Packet 14715
    internal class SendGlobalChatLineMessage : Message
    {
        public SendGlobalChatLineMessage(Device device, Reader reader) : base(device, reader)
        {
        }

        public string Message { get; set; }

        internal override void Decode()
        {
            this.Message = this.Reader.ReadString();
        }

        internal override async void Process()
        {
            if (Message.Length > 0 && Message.Length < 200)
            {
                if (Message[0] == '/')
                {
                    object obj = GameOpCommandFactory.Parse(Message);
                    if (obj != null)
                    {
                        string player = "";
                        if (this.Device.Player != null)
                            player += " (" + this.Device.Player.Avatar.UserId + ", " +
                                      this.Device.Player.Avatar.AvatarName + ")";
                        ((GameOpCommand) obj).Execute(this.Device.Player);
                    }
                }
                else
                {
                    long senderId = 

Open in new window

0
good day,
i am developing an application using window form
i am new to graph in visual studio c#,
i want to know if there is a way or a method i can use to  find the (x,y) coordinates of the peaks and valleys of a graph?
i have attached a file containing a picture of my graph.
graph.png
0
var test1 = Convert.ToInt32(Session["SID"]);
Line 90:                       //  int ist = EAdapter.Insert(Convert.ToInt32(Session["SID"]), txtclgname.Text, txtErlno.Text,
Line 91:                         int ist=EAdapter.Insert(Convert.ToInt32(Session[test1]), txtclgname.Text, txtErlno.Text,
Line 92:                           drpsem.SelectedItem.Text, drpEdu.SelectedItem.Text, drpBranch.SelectedItem.Text, drpPassyear.SelectedItem.Text,
Line 93:                           float.Parse(txtCGPA.Text), drpreqskill.SelectedItem.Text, txtExSkill.Text, resume);

Open in new window

0
Hi, i am working on mvc 5 project, so  now  i am trying to display the list of images in webgrid . I stored that images into datatable and after that how i display those images in webgrid. i don't  know more about that because this things are new for me.
C# Code:
    
    public ActionResult PhotoViewer(string cid)
        {
            ChildEdit cd = new ChildEdit();
            cd.Cid = cid;
            List<ChildEdit> photolist = new List<ChildEdit>();
            if (cd.Cid != null)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
                SqlCommand cmd = new SqlCommand("spGetChildPhotos", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@cid", Convert.ToInt64(cd.Cid));
                SqlDataReader dr;
                con.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    cd.Photo = (byte[])dr["photo"];
                    var stream = new MemoryStream(cd.Photo);
                    cd.Photostr = stream;
                    cd.Cid = dr["cid"].ToString();
                    photolist.Add(cd);
                }
           }
            return View(photolist);
        }
            {

Open in new window

and ViewCode :

 @grid.GetHtml(htmlAttributes: new { id = "lwebgrid" }, tableStyle: "webgrid-table",
    headerStyle: "webgrid-header",
    footerStyle: "webgrid-footer",
    alternatingRowStyle: "webgrid-alternating-row",
    selectedRowStyle: "webgrid-selected-row",
    rowStyle: "webgrid-row-style",
    mode: WebGridPagerModes.All,
    columns: grid.Columns(
         grid.Column("Cid", "Id", format: @<text><span class="display-mode">
                <label id="lblCid">@item.Cid</label>
            </span>
            <input type="text" readonly class="edit-mode getcid lblid" id="txtlCid" value="@item.Cid" /> </text>, style: "col2Width"),
        grid.Column("Photo", "Photo")
     ))

Open in new window

0
   protected void Page_Load(object sender, EventArgs e)
        {

            CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(), Session["QUALI"].ToString(), Session["skill"].ToString());
            if (CDT != null)
            {
                if (CDT.Rows.Count > 0)
                {
                    Session["CID"] = CDT.Rows[0]["CID"].ToString();
                }
                else
                {
                    DataList3.DataSource = CDT;
                    DataList3.DataBind();
                }
            }

        }

Open in new window

0
Hi Experts ,

Please see the below screenshot,i need to make a grid using gridview to bind the data.also filter the data acoording to screen shot.
In gridview its have a sorting and above that its have a filter.
could you please provide the solution for the same.
asp.net and c#

Thanks
gridviewfilter.PNG
0
I have created a SmartDeviceProject in visual c#.
I have set Target platform "Windows mobile 5.0 pocket pc sdk" and
.net compact framework version 2.0.
After create project, i create installable cab file for symbol mc70.
I  installed it to mc70, it shows install successfully,
but when try to open from start up menu it gives error "This application (testproject.exe) requires a newer version of the microsoft compact framework than the version installed on this device".
Please tell me for mc70 which .net compact framework version is supported ?
0
hi good day
i am using window form app
the value i insert can only be shown in the treeview after i exit the app and run it again. i am struggling to find a way to be shown in the treeview immediately after i inserted them. please i need assistance.
 this my  code for populating the treeview,
 i have created two methods which are working:
one another one for binding
  the other  for populating the treeview
 and i called those two method in my load event

 public void populatebind(DataTable dt, int parid, TreeNode Node)
        {
            foreach (DataRow item in dt.Rows)
            {
                
                TreeNode tnode = new TreeNode
                
                {
                    Text = item["Name"].ToString(),

                    Name = item["Id"].ToString()
                };
                
                if (parid == 0)
                {
                    treeView1.Nodes[0].Nodes.Add(tnode);
                    
                    tnode.Tag = "Client";

                    DataTable dt1 = this.binddata("select id, Name from [tbl_project] where cId =" + tnode.Name);
                    count = 1;
                    this.populatebind(dt1, count, tnode);


                }
                else if (parid == 1)
                {

                    Node.Nodes.Add(tnode);
                    tnode.Tag = "Project";

                    DataTable dt2 = this.binddata("select Id, Name  from [tbl_batches] where completed =" + 

Open in new window

0
I have images from 2 different folders that I want to display in a table data. I did this but it says ' missing start tag.. how do u get images in 2 folders to get in a tabledata??
    <td><img src="../EventImages/Events/<%#Eval("images") %>" 
                    <img src="../ProductImg/<%#Eval("images") %>" height="100" width="100" /></td>

Open in new window

INITIAL full code
   <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">Full Detail</div> 
        <asp:Repeater ID="r1" runat="server">
            <HeaderTemplate>
               <table class="table">
                   <thead>
                   <tr>
                       <td>image</td>
                       <td>name</td>
                       <td>price</td>
                       <td>quantity</td>
                   </tr>
                       </thead>
                   <tbody>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                <td><img src="../EventImages/Events/<%#Eval("images") %>" 
                     height="100" width="100" /></td>
                <td><%#Eval("name") %></td>
                <td><%#Eval("price") %></td>
                <td><%#Eval("qty") %></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </tbody>
                </table>
            </FooterTemplate>
        </asp:Repeater>

        <asp:Label ID="l1" runat="server" Text=""></asp:Label>
                    </div>
               </div>

Open in new window

0

C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).