Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

How to fire evet from static-method

$
0
0

Hi

I have C# class including events interface. The class instance is targeted to be used in VBA.

The class has Read Thread static method which calls OnMyEvent non-static method to fire

MyEvent.

      public static void Read()  // must be static
        {
            while (_continue )
            {
                try
                {
                    if (_init)
                    {
                        RxData = _serialPort.ReadLine();
                        OnMyEvent(RxData);  // <<<<<<<<<<< Error: An object reference is required for the non-static field, method, or property 
                     }
                }
                catch (TimeoutException) { }
            }
        }

I searched the WEB but nothing solve  my issue. I  tried :

Singleton  (but i have to "new" in VBA)

pass arg by ref does not do it (same error)

create new class instance (_inst.MyEvent) does not work

The said Error moves around as i try to modify methods to non-static

What do i do ?

Your help will be appreciated

Thanks


How Can i create a new Web UI Control from Scratch...?

$
0
0

I want to design a new Web UI Control (Like a textbox, checkbox, button ..) I want to develop a new control. 

My Concern is completely about, how it can be developed, which language, What are the tools used for doing the same...Please dont bother about the control i'm asking about.

Preferably .NET technologies.


M Praveen

Serial port reconnecting

$
0
0

Hi,

My application need to communicate a periferial using RS-232. My computer is connected to the periferial by RS232-to-USB of Prolific.

I’m trying to reconnect after the following scenario:

I take the RS232 cable out of the computer.

I run my application and try to connect to the port.

Of course, the connection fails.

I connect the RS232 cable to the computer.

I try to connect the port again.

And again, I fail.

The only way I can connect now is by closing the application and running it again.

It looks like I fail to clean something, but I don't know what...

My close function looks like this:

public

overridevoid Close()

{

Log4NetWrapper.Instance.LogDebug("Rs232Communicator","Closing","");

try

{

if (m_Port !=null&& m_Port.IsOpen == true)

{

m_Port.Close();

}

m_Port.Dispose();

m_Port =

null;

}

catch (Exception ex)

{

System.Windows.Forms.

MessageBox.Show(ex.Message +"\r\n"+ ex.StackTrace);

}

}

How to get information from the idle state of wlan in C# windows 7

$
0
0

In my project I need to detect the idle state of wlan in windows 7, but failed because the class I use System.Net.NetworkInformation Namespace. NET.

The class specifies the operational state of the network interface: "Dormant, Down, LowerLayerDown, notPresent, Testing, Unknown, Up"

Link: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.operationalstatus.aspx

None of these states seem to correspond to the idle state of wlan.

Researched how information of energy states but only found the. Net compact framework in: enum _CEDEVICE_POWER_STATE. Link: "msdn.microsoft.com/pt-br/library/aa932261.aspx

I tried to do a WMI query on "Win32_NetworkAdapter" link: "http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx" field "uint16 Availability" for "Meaning Value = 14 = Power Save - Low Power Mode" or "Value Meaning = 15 = Power Save - Standby" but the query only returns "value = 3 = Meaning Running or Full Power" even the network adapter off.

SqlConnection.StateChange is not firing when sever is closing

$
0
0
Hello. At the beginning server is working and i get first event from "StateChange". Then i close server but i don't receive event about it from "StateChange". I receive it only if i try to execute some sql command. Why is it? Is it possible to receive this event momentarily?

Getting the admin rights in C#

$
0
0
Hello everyone,


My application programmed in C# copy, move, and create files.... but if the user choose to use it on the disc where windows is installed, the process have to have the admin rights. (Otherwise : Access denied)

The current solution is that the user has to run the application "as Administrator". But it would be more friendly to ask for the admin rights even if the user has no checked the "Run as admin".

Question :
How could I ask for admin rights before my application is launched by the user ?

Profiling ASP.NET applications.

$
0
0

Hi

I have gone through this article for creating custom .NET profiler(http://www.codeproject.com/Articles/15410/Creating-a-Custom-NET-Profilerhttp://) usingICorProfilerCallback. But here in this article we have created separate application to launch the application that needs to be profile but what about when profiling asp.NET applications.

Can anyone guide me or give suitable steps on How we can  create custom profiler using ICorProfilerCallback to profile ASP.NET application?

I am facing problem in file uploading through sftp on remote server

$
0
0

I am facing the problem in connecting the port. I am pasting my code here------full code. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using Tamir.SharpSsh;
using Tamir.Streams;
using Org.Mentalis.Security;
using System.IO;
using System.Xml;
using System.Data;
using Tamir.SharpSsh.jsch;
using System.Collections;
using Tamir.SharpSsh.java.net;
using Tamir.SharpSsh.jsch.jce;
using System.IO.Compression;
using Org.Mentalis.Security.Cryptography;
using Org.Mentalis.Security.Ssl;
using Org.Mentalis.Security.Certificates;
using System.Net.Sockets;










namespace ftpmsg
{
    public partial class frmsftpfiletransfer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            bool result;

           result= FileUploadUsingSftp();
           if (result==true)
           {
               lbl_Msg.Text = "File Uploaded Successfully";
           }
           else
           {
               lbl_Msg.Text = "File not Uploaded Successfully";
           }

        }

       

        public bool FileUploadUsingSftp()
        {
            try
            {

           
            string host = "193.203.230.152";
            int port = 20022;
            string user = "BJ25F";
            string pass = "";
            string privateKey = Server.MapPath("keys/xyz_PrivateKey");
            
            SftpPlugin sftp = new SftpPlugin(host, port, user, pass, privateKey);
                

            // upload a file
            //bool done = sftp.UploadFile(@"D:\Req1.xml", "/");
            bool done = sftp.UploadFile(@"D:\CRYSTAL.txt", txtRemotepath.Text);

            return done;
            }
            catch (Exception)
            {
                
                SftpException.SaveToEventLog("Parameters not accepted Successfully"); 
                return false;
            }
        }

    }

    public class SftpPlugin
    {
        // Private fields
        private int _port;
        private string _privateSshKeyPath;
        private Tamir.SharpSsh.Sftp _tamirSftp;
        
        // Constructors
        public SftpPlugin(string host, string username, string password)
        {
            this._tamirSftp = new Sftp(host, username, password);
            this._port = 20022; // default Port 22
        }

        public SftpPlugin(string host, int port, string username, string password)
        {
            this._tamirSftp = new Sftp(host, username, password);
            this._port = port;   // Specific port
        }

        public SftpPlugin(string host, int port, string username, string password, string privateSshKeyPath)
        {
            this._tamirSftp = new Sftp(host, username, password);
            this._port = port;
            this._privateSshKeyPath = privateSshKeyPath;
        }

        // Private Methods
        private void Connect()
        {
            
            try
            {
                             
            // add the private Key if it is specified
            if (!string.IsNullOrEmpty(this._privateSshKeyPath))
            {
                this._tamirSftp.AddIdentityFile(this._privateSshKeyPath);
               
            }
            this._tamirSftp.Connect(this._port);==============//facing error here --port is not connected.//

            SftpException.SaveToEventLog(" Port Connected successfully");
                
          }
            catch (Exception)
            {

                SftpException.SaveToEventLog(" Port not Connected successfully"); 
            }

        }

        // Public Methods

        // upload a list of files to a remote path
        public bool UploadFiles(string[] files, string toRemotePath)
        {
            if (!this._tamirSftp.Connected)
            {
                this.Connect();
                
            }

            try
            {
                this._tamirSftp.Put(files, toRemotePath);
                return true;
            }
            catch (Exception ex)
            {
                
                SftpException.SaveToEventLog(" Files not  Uploaded Successfully"); 
                return false;
                
            }
            finally
            {
                this._tamirSftp.Close();
            }
        }

        // upload a file to a remote path
        public bool UploadFile(string file, string toRemotePath)
        {
            if (!this._tamirSftp.Connected)
            {
                this.Connect();
            }

            try
            {
                this._tamirSftp.Put(file, toRemotePath);
                return true;
            }
            catch (Exception ex)
            {
                
                SftpException.SaveToEventLog(" File not  Uploaded Successfully"); 
                return false;
            }
            finally
            {
                this._tamirSftp.Close();
            }
        }

        // download a list of files to a local path
        public bool DownloadFiles(string[] files, string toLocalPath)
        {
            if (!this._tamirSftp.Connected)
            {
                this.Connect();
            }

            try
            {
                this._tamirSftp.Get(files, toLocalPath);
                return true;
            }
            catch (Exception ex)
            {
               
                SftpException.SaveToEventLog(" Files not  downloaded Successfully"); 
                return false;
            }
            finally
            {
                this._tamirSftp.Close();
            }
        }

        // download a file to a localPath
        public bool DownloadFile(string file, string toLocalPath)
        {
            if (!this._tamirSftp.Connected)
            {
                this.Connect();
            }

            try
            {
                this._tamirSftp.Get(file, toLocalPath);
                return true;
            }
            catch (Exception ex)
            {
                SftpException.SaveToEventLog(" File not Uploaded"); 
                return false;
            }
            finally
            {
                this._tamirSftp.Close();
            }
        }

        // list the files of a remote location
        public string[] ListFiles(string remotePath)
        {
            if (!this._tamirSftp.Connected)
            {
                this.Connect();
            }

            string[] files = new string[] { };
            try
            {
                files = this._tamirSftp.GetFileList(remotePath).Cast<string>().ToArray();
            }
            catch (Exception ex)
            {


                SftpException.SaveToEventLog(" files of a remote location not shown");
            }
            finally
            {
                this._tamirSftp.Close();
            }
            return files;
        }

       
    }
}



Print ticket service failed to bind to printer Win 32 Error

$
0
0

I have fully functioning and stable XPS creation (.Net 4) and printing (.Net 4.5)  server side web services, however I do have one issue. I also have an admin web site (asp.net mvc 4 on IIS7.x) that iterates through my client's print servers, extracting the print queues and retrieving the print capabilities (queue.getprintcapabilitiesasxml) which are then deposited in an SQL database for print job use. This site is run when support adds or removes printers or changes printer drivers on print servers so that the tray namespaces and URIs are always correct for each printer.

The issue is this...When I run this admin code from VS2010 (.Net 4) on my desktop (win 7 x64)everything works correctly and I receive all the printer information I require, however when I deploy to IIS (7.5 2008 R2) and run the site, one print server (virtual 2008 R2) reports that "Print ticket service failed to bind to printer Win 32 Error: Unknown printer driver" for the printers I'm targeting (Sharp printers). As stated, this print server is virtual whereas the others are real and Sharp printers exist on the other print servers. I thought this might be a permissions issue so I tried running the site's app pool identity as my own domain account, which didn't work, so I tried impersonation and that didn't work. The virtual print server flat out refuses to pass info back to the IIS server but will happily pass it back to my desktop (all other things being equal). I'm at a bit of a loss on how to investigate this, so I'm asking for help here.


how to add google map in asp.net with location?

how to add facebook, twitter button in asp.net??

How to upload Video file in asp.net

Winsock Control

$
0
0
How can we implement Winsock control in C# (VS2012)?

Reactive Extensions Throttle method

$
0
0

I want to Throttle a method call.

This method is called several times (and it writes to a file), so would be nice if it was called after 2 or 3 seconds.

I tried this, but it is calling each time:

Observable
                    .FromAsync(() => configurationRepository.UpdateConfiguration(sessionManager.CurrentTransmission))
                    .Throttle(TimeSpan.FromSeconds(2))
                    .Subscribe();

And the method signature:

public interface ITransmissionConfigurationRepository
    {
        Task UpdateConfiguration(Transmission transmission);
    }


Take a look at WPF FlashMessage
About.me

how to reduce the image file size


Gridview not showing media

$
0
0

I have a simple page with a GridView.  At run time I add mediaelements to it but they do not show (though there are blank place holders for each)

If I do the same thing declaratively, they show.

Is there some additional property I am missing?

ServiceController Class - Getting Startup Type

$
0
0

I have a console app that displays information about the services on a computer using the ServiceController class.  

The only thing I cannot pull is the Startup Type, e.g., Manual, Automatic.

using System;
using System.ServiceProcess;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ServiceController[] sController = ServiceController.GetServices();
                Console.WriteLine("Running Services");
                Console.WriteLine("----------------");
                foreach (ServiceController sc in sController)
                {                                                        
                        Console.WriteLine(sc.ServiceName);
                        Console.WriteLine(sc.Status);
                        Console.WriteLine(sc.ServiceType);
                        Console.WriteLine(sc.DisplayName);
                        Console.WriteLine(sc.ServiceType);
                        Console.WriteLine("----------------");                                      
                }
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                // handle ex
            }
        }
    }
}

Anyone know how to display the Startup Type of a service ?

Thanks

open fileS from desktop in single instance app

$
0
0

Hello,

I have an app that is a single instance application (using the Process class).

I succeded to lauch the app the first time by double clic on one of its doc file.

Now, I want that when the user double click on the icone of one of its doc files, that the already running app opens this file.

How to do this in C#?

thanks in advance

Pascal

How to run Outlook VBA sub from Outlook dll

$
0
0

Hi

I have c# COM dll (Net 4 for client) for Outlook  2007

The dll has to run VBA sub (both dll & sub run on Outlook)

invoke method crashes Outlook, so i try

 System.Type objAppType = System.Type.GetTypeFromProgID("Outlook.Application");
 object objApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                Debug.Write  ("1");
 objAppType.InvokeMember("CB", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, objApp, strArr);
                Debug.Write  ("2");
This does not run sub CB (debug print / write do not work)

No exception is caused by this code

Any help would be appreciated

Thanks




implement audio/video streamin in c#

Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>