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

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;
        }

       
    }
}



Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

$
0
0

I am working on a windows forms application. when I run the application on windows 8 (VS2012), the application runs upto an extent and then crashes, giving the exception "{"Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}".

I am unable to include sqlite3 dll in the references. when I try adding it and change the Copy Local attribute to True, I am unable to do it as whenever I build the solution, this attribute gets changed to False automatically. also when I try adding SQLite3 through the release\x64 folder, I get an error that the file is not accessible. kindly help me fix this issue!!

How To Override The DigitShapes Setting In C# .NET 4.0? (Use Native Digits Setting in Region and Language Dialog)

$
0
0

I have a C# form application that needs to override the DigitShapes (Use Native Digits) setting.  What I need to achieve is to always display digits using their original shapes.  So I need to always run with the DigitShapes set to "None", regardless of the Use Native Digits setting in the "Region and Language" setting in Windows.  (I am testing in Windows 7).

For example, if the character value is between 0x30 and 0x39 I need to display the numeric using the western Arabic numerals "123" etc. (http://en.wikipedia.org/wiki/Arabic_numerals)   If the character value is between 0x660 and 0x669, I want it to display with the Indic glyph (http://en.wikipedia.org/wiki/Eastern_Arabic_numerals)

In the windows "Region and Language" dialog, when "Use Native Digits" is set to "Never", then the application numerics always displays as desired.  When "Use Native Digits" is set to "Context", then values in the 0x30 to 0x39 will display with the Indic glyph when the direction is right to left (RTL) or if it is preceded by a BiDi character with a RTL directionality.  My understanding is that the DigitShapes setting maps to the "Use Native Digits" setting in the "Region and Language" dialog.

By default, the arabic locales default "Use Native Digits" to "Context".  I want to force my application to always run as if the setting is "Never".

I have been attempting to override the locale setting in my application to force DigitShapes to be "none".  The sample code below gets the current locale context and overrides the DigitShapes and then resets the culture for the application.  In the debugger I can see that if I query the thread culture, it does indeed have DigitShapes set to "None".  However, numerics are still being substituted during display in a RTL environment.

I have tried calling ClearCachedData, but that doesn't seem to help.  Is this a bug or am I missing a step to force my application to never substitute digits? 

Sample code

        static void Main(string []args)
        {            
            System.Globalization.CultureInfo cinfo = (System.Globalization.CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            Thread.CurrentThread.CurrentCulture.ClearCachedData();
            Application.CurrentCulture.ClearCachedData();
            cinfo.NumberFormat.DigitSubstitution = System.Globalization.DigitShapes.None;
            Thread.CurrentThread.CurrentCulture = cinfo;
            Thread.CurrentThread.CurrentUICulture = cinfo;
            Application.CurrentCulture = cinfo;           

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyForm(args));
        }

Help is appreciated.

Robert

It's very urgent for me.--hi, anybody plz reply to my question and resolve my problem.

$
0
0

hi, anybody plz reply to my question and resolve my problem of sftp file transfer on remote server. .It's very urgent for me. i have assigned this task and not getting exact solution. 

1. I have converted my private SSH-2 RSA key to Open ssh format thru putty generator. 

2. but still facing problem to resolve it. when code is running it's giving port is not connected successfully.


Error connecting to SQL Server 2000 database using System.Data.SqlClient.SqlConnection after upgrading to .NET Framework 4.5

$
0
0

After upgrading from .NET Framework 4 to 4.5, my application is no longer able to connect to SQL Server 2000 databases using a System.Data.SqlClient.SqlConnection object.  The error I receive when trying to connect is:

*******************

Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=25; handshake=14974;

*******************

I am still able to connect to SQL Server 2005 and later databases after the .NET 4.5 upgrade.  Prior to the upgrade, I could connect to SQL Server 2000 databases.  I am assuming that SQL Server 2000 connections are no longer supported in the System.Data.SqlClient.SqlConnection class as of .NET 4.5.  Could someone please verify that this is indeed the case or is there something I can do in my connection string or somewhere else to allow me to connect to a SQL Server 2000 database using .NET 4.5?

Thanks

Cute question mark is keep appearing at the end of a string, and no longer I like it.

$
0
0

It's been a day I can't get rid of those cute question marks. I definitely need a help with them.

Working environment [VS 2010, Oracle 11g].

Task is to store and retrieve huge text from Oracle DB through win32 API into windows form.

In Database I've a BLOB field for the text. In my form (C#) I have a Text Box for the text.

Form sends the text to win32 API then win32 API has to store it in database.

After all, another Form (C#) retrieves the text from database.

Code goes like following.

//Win32 storing the text (C++) wstring theText=get_the_text(); //(gets the text from Form) string strText=convert_wstring_to_string(theText); //(type conversion)

store_in_database(new ByteArray((char*)strText.c_str(), strText.length(), true));

//---------------------------------------------------------------------------------

//Form retrieving the text (C#)

String theText=System.Text.Encoding.UTF8.GetString((byte[])get_from_database());

TextBox txtDisplay.Text=theText;

In code, every self-explanatory function does what they suppose to do. / get_the_text(), store_in_database() ...etc /

As a result I got everything I want except question mark is appearing at the end of my Text Box. Every time I update the text, 1 more appears at the end of the Text Box.

So from where question mark come up? How to get rid of the question mark?

Any comment, suggestion or hint is welcomed :)

I don't like them ----> ��������



enableiehosting

$
0
0
Looking for guidance on why loading browser hosted controls was turned off by default in .Net 4.5.  From a compatibility perspective this is breaking some enterprise applications.  I understand the registry key needed to turn it back on.  I am having trouble finding documentation on the repercussions of enabling it.

adam

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.



Visual Studio 2010 - Setup and Deployment Project not working properly

$
0
0

I am trying to create setup project using VS2010. In my Application Folder, I put some files. In my System Folder, I also put some files. I build the project successfully and I got msi file. I have installed the application using generated files. So far so good.

But when I check the time stamp of files in Application Folder and System Folder, it is changed. It puts the current time. For example, test.txt file was in the source place was 09/19/2009, but after installation it put the today's date 06/11/2010.

When I create the same msi project using VS2008, it works like expected. There is no problem at all with VS2008.

Is this bug in VS2010.

Kind Regards,

Rajan Kumar

 


Rajan

wrong clock time

$
0
0

When I look at the clok time when I received an email there is a wrong time indicated  that is + 4 hours as if my computer would stand in an other time zone like england instead of being in the east coast of america 

what can I do for this?

class MSFT_NetAdapter supports windows 7?

$
0
0

Anyone who has ever used can tell me if the class MSFT_NetAdapter supports windows 7? 

I am used C#

SignedXml namespace does not exist

$
0
0
Hello,

I found a strange problem today: I was writting a program in C# on my WindowsXP 64 machine. I have .NET 1.1, 2.0 and 3.5 installed. While I tried to sign xml document with the following code:

System.Security.Cryptography.Xml.SignedXml signedXml = new System.Security.Cryptography.Xml.SignedXml(postDocument); 


i got the following error:

"The type or namespace 'SignedXml' does not exist in the namespace System.Security.Cryptography.Xml."

At the beginning I was working with .NET 3.5 in VS 2008 PRO, but the same problem existed in .NET 2.0. It seemed to me like I was missing some dll on my machine. So I tried the same code on VS 2003 on 32 bit XP using .NET 1.1. But the code generated the same error.

Any ideas?

Change GAC view

$
0
0

Hi,

how to change the view for GAC, In my server system "C:\Windows\assembly" consists of folders and sub folders view,

Need to change that view for to see all assemblies..

anyone help me to change this view ASAP.

Regards,

RK

System.ComponentModel.Win32Exception "Access Denied" retrieving process information as local admin using impersonation

$
0
0

Hi everyone.

I am encountering an issue when trying to get other processes informations from my app. This app is an "updater". When it starts, it checks if the process to update is running. And here is the issue. Some informations on the running processes throw a System.ComponentModel.Win32Exception "Access denied" Exception. I was able to understand the reason of the exception : the updater is lauched from a "user" account and the user cannot read other user's processes. Because the updater runs in a Terminal Service session, other users may have the app to update running. If that is the case, the updater should warn the user, but instead of doing it, it crashes when reader the running process info.

After reading a lot about over the internet, I decided to use impersonation to execute the updater so that it will execute as a different account. Because the updater must access a network share, I set a domain administrator account.

The code runs fine, the impersonation works, but the exception is still there, even when the the code is executed with the domain admin account. I also tried to put the domain admin account in the local "Administrators" group.

So... I don't understand what is going wrong...

Can you help me please ?

(The updater runs on a Windows Server 2003 x86, the .NET framework is the 3.5)

Here is the simplified code that trows the exception :

WrapperImpersonationContext c =newWrapperImpersonationContext("MyDomain","MyDomainAdmin","MyPassword");

int errorCode =0;

c.Enter(out errorCode);// Impersonation...

Console.WriteLine(Environment.UserName) ; // = MyDomainAdmin, Impersonation OK!

// Looking for running process called "test". It may return mine or other users processes

Process[] ret = Process.GetProcessesByName("test");List<Process> retList =newList<Process>();for(int i =0; i < ret.Length; i++){

// The process here is a process that belongs to another user, that's why I get an exceptionFileInfofi=newFileInfo(ret[i].MainModule.FileName);// System.ComponentModel.Win32Exception!!! Access denied on MainModule...}

Here is theWrapperImpersonationContext class code :

usingSystem;usingSystem.Runtime.InteropServices;usingSystem.Security.Principal;usingSystem.Security.Permissions;usingSystem.ComponentModel;namespaceCommon.ApplicationUpdater{publicclassWrapperImpersonationContext{[DllImport("advapi32.dll",SetLastError=true)]publicstaticexternboolLogonUser(String lpszUsername,String lpszDomain,String lpszPassword,int dwLogonType,int dwLogonProvider,refIntPtr phToken);[DllImport("kernel32.dll",CharSet=CharSet.Auto)]publicexternstaticboolCloseHandle(IntPtr handle);privateconstint LOGON32_PROVIDER_DEFAULT =0;privateconstint LOGON32_LOGON_INTERACTIVE =2;privatestring m_Domain;privatestring m_Password;privatestring m_Username;privateIntPtr m_Token;privateWindowsImpersonationContext m_Context =null;protectedboolIsInContext{get{return m_Context !=null;}}publicWrapperImpersonationContext(string domain,string username,string password){ m_Domain = domain; m_Username = username; m_Password = password;}[PermissionSetAttribute(SecurityAction.Demand,Name="FullTrust")]publicboolEnter(outint errorCode){ errorCode =0;if(this.IsInContext)returntrue; m_Token =newIntPtr(0);try{ m_Token =IntPtr.Zero;bool logonSuccessfull =LogonUser( m_Username, m_Domain, m_Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,ref m_Token);if(logonSuccessfull ){WindowsIdentity identity =newWindowsIdentity(m_Token); m_Context = identity.Impersonate();}else{ errorCode =Marshal.GetLastWin32Error();returnfalse;}returntrue;}catch(Exception ex){ errorCode =(int)Marshal.GetHRForException(ex);returnfalse;}}[PermissionSetAttribute(SecurityAction.Demand,Name="FullTrust")]publicvoidLeave(){if(this.IsInContext==false)return; m_Context.Undo();if(m_Token !=IntPtr.Zero)CloseHandle(m_Token); m_Context =null;}}

}

Thank you for helping me!

Best regards.


Matteo, .NET Developer and System Engineer

can we load Microsoft.Office.Interop.Word dynamically and create Word Document in c# or Vb.net

$
0
0

Hi EveryOne,

can we load Microsoft.Office.Interop.Word dynamically and create Word Document in c# or Vb.net .

I would like to add dynamically and open word document and create word documents.

Is it possible ? If yes please provide me the links.

I loaded interop dynamically , but unable to create instances and open word doc.. etc.

many Thanks


s.giribabu


i can't seem to figure out any hper-v wmi ip addresses configured on its interfaces.

$
0
0
 i can't seem to figure out any hper-v  wmi ip addresses configured on its interfaces.

Crystal Report for microsoft visual basic 2010 express

$
0
0

hi!

I am doing my project which is inventory. I am using microsoft visual basic 2010 express and i'll be needing crystal report. According to my research ms visual basic 2010 express does not support crystal report. Is this true??? If does not, can somebody give me link/s which i can download the crystal report.

Thank you


Regards, Nithin Varghese

VB.Net Component suspended

$
0
0

We are migrating from IIS 6 to IIS 7. Along with this, if there is any VB components in ASP pages, we are migrating to VB.Net.
One such ASP application got migrated to IIS7. It has one VB component.
We have migrated it to VB.Net.
As the component access third party dll  which is in 32 bit. We have complied the VB.Net component in 32 bit with target .Net framework as 4.0.
In ASP setting we have enabled 32 bit. Now the issue is,
When a single user is using the page, everything is working fine.
When the multiple user logs in or the same user opens the multiple browser and access the same site which uses the component, the component is hanging. There is no response from the component. After a long time, ASP page displays the error "Internet Explorer cannot display the webpage."
There are not public variables in the component. There are some public functions at module level.
Can someone please give your suggestions to get us out of this issue?


How to find MAC ID of the device connected to system?

$
0
0

I Have connected two antena devices through rs232 cable to my system,now i need to get the device MAC Id of two antena device which is connected to my system through rs232 cable.

How do i do this?

am a newbie in this serial port programming.

i've searched every where but every one getting MAC ID through IP Address but in my case i have connected two devices directly to my system. so how do i find MAC ID of these two devices?

Any suggestion would be of great help.

Thanks


Arjun

Convert PDF to Jpg

$
0
0

is there a way to convert PDF to JPG?

Viewing all 8156 articles
Browse latest View live