Click here to Skip to main content
15,888,220 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to import excel sheet data into postgresql database table in C# Pin
manchanx3-Mar-15 2:38
professionalmanchanx3-Mar-15 2:38 
QuestionRe: How to import excel sheet data into postgresql database table in C# Pin
ZurdoDev3-Mar-15 2:46
professionalZurdoDev3-Mar-15 2:46 
AnswerRe: How to import excel sheet data into postgresql database table in C# Pin
V.3-Mar-15 20:19
professionalV.3-Mar-15 20:19 
QuestionDoes the .Net scheduled Timer has a vb version? Pin
PHdeviloth2-Mar-15 20:55
PHdeviloth2-Mar-15 20:55 
QuestionRe: Does the .Net scheduled Timer has a vb version? Pin
Richard MacCutchan2-Mar-15 21:25
mveRichard MacCutchan2-Mar-15 21:25 
AnswerRe: Does the .Net scheduled Timer has a vb version? Pin
F-ES Sitecore2-Mar-15 22:02
professionalF-ES Sitecore2-Mar-15 22:02 
AnswerRe: Does the .Net scheduled Timer has a vb version? Pin
ZurdoDev3-Mar-15 2:45
professionalZurdoDev3-Mar-15 2:45 
QuestionNeed help on FTPS file transmission using X509 Certificates Pin
Satheesh Kumar Subramanian2-Mar-15 18:03
Satheesh Kumar Subramanian2-Mar-15 18:03 
I am developing a FTPS component in my ASP.Net application.
We configued the Personal Certificate,Intermediate Certificate and Root Certificate in Server and Client machine MMC console.
I am stuck in to implement the same as I am getting below error:

--------------------------------------------------------
.
.
.
System.Net Information: 0 : [6876] SecureChannel#65124268 - Certificate is of type X509Certificate2 and contains the private key.
System.Net Information: 0 : [6876] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc = System.Net.SecureCredential)
System.Net Error: 0 : [6876] AcquireCredentialsHandle() failed with error 0X8009030D.
System.Net Information: 0 : [6876] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc = System.Net.SecureCredential)
System.Net Error: 0 : [6876] AcquireCredentialsHandle() failed with error 0X8009030D.
System.Net.Sockets Verbose: 0 : [6876] Socket#19949373::Dispose()
System.Net Information: 0 : [6876] FtpWebRequest#64456428::(Releasing FTP connection#53218812.)
System.Net Error: 0 : [6876] Exception in FtpWebRequest#64456428::GetRequestStream - The remote server returned an error: 234 SecurFTP: SSL starting
..
at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.IO.Stream.Close()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetRequestStream()
System.Net Verbose: 0 : [6876] Exiting FtpWebRequest#64456428::GetRequestStream()
System.Net Information: 0 : [1320] ServicePoint#797974 - Closed as idle.
--------------------------------------------------------

Please help me to solve this issue as it is urgent.
Below is my sample code:
---------------------------------------------------------
public bool FileTransferStatus(FileInfo oFile, string localCertificateNames, bool isFileType, out string statusMessage)
        {
            FtpWebRequest ftpRequest;
            FtpWebResponse ftpResponse;
            try
            {
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(FTPSite + CurrentDirectory + oFile.Name);
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                ftpRequest.Proxy = null;
                ftpRequest.UseBinary = true;
                ftpRequest.Credentials = new NetworkCredential(UserName, Password);
                ftpRequest.KeepAlive = KeepAlive;
                ftpRequest.EnableSsl = UseSSL;
                ftpRequest.UsePassive = true;

                if (UseSSL)
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
                    
                    List<string> listLocalCertificates = localCertificateNames.Split(',').ToList<string>();
                    if (isFileType)
                    {
                        foreach (string localCertificate in listLocalCertificates)
                        {
                            string currentCertificate = localCertificate.Replace("\n", "").Replace("\t", "").Replace("\r", "");
                            X509Certificate certificate = X509Certificate.CreateFromCertFile(System.AppDomain.CurrentDomain.BaseDirectory + currentCertificate.Trim());
                            ftpRequest.ClientCertificates.Add(certificate);
                        }
                    }
                    else
                    {
                        X509Store storeRoot = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                        storeRoot.Open(OpenFlags.ReadOnly);
                        X509Store storePersonal = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                        storePersonal.Open(OpenFlags.ReadOnly);
                        List<string> listSerialNumbers = localCertificateNames.Split(',').ToList<string>();

                        foreach (string sn in listSerialNumbers)
                        {
                            string serialNumber = sn.Trim().ToUpper();
                            
                            X509CertificateCollection certificates = storeRoot.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, false);

                            if (certificates.Count == 0) // Not in root store
                            {
                                certificates = storePersonal.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, true);
                            }

                            if (certificates.Count == 0) //Not in personal store
                            {
                                throw new Exception(string.Format("Certificate {0} not found", serialNumber));
                            }

                            storeRoot.Close();
                            storePersonal.Close();

                            X509Certificate certificate = certificates[0];
                            ftpRequest.ClientCertificates.Add(certificate);

                        }
                    }
                }

                //Selection of file to be uploaded          
                byte[] fileContents = new byte[oFile.Length];
                using (FileStream fr = oFile.OpenRead())
                {
                    fr.Read(fileContents, 0, Convert.ToInt32(oFile.Length));
                }
                
                using (Stream writer = ftpRequest.GetRequestStream())
                {
                    writer.Write(fileContents, 0, fileContents.Length);
                }

                //Gets the FtpWebResponse of the uploading operation          
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpResponse.Close();
                ftpRequest = null;

                statusMessage = "Uploaded successfully";

                return true;
            }
            catch (Exception webex)
            {             
                statusMessage = webex.Message;

                return false;
            }

        }

---------------------------------------------------------
Friendly,
Satheesh

AnswerRe: Need help on FTPS file transmission using X509 Certificates Pin
Richard MacCutchan2-Mar-15 21:24
mveRichard MacCutchan2-Mar-15 21:24 
QuestionStreamReader in TcpListener Pin
Member 114922552-Mar-15 7:14
Member 114922552-Mar-15 7:14 
AnswerRe: StreamReader in TcpListener Pin
Paulo Zemek2-Mar-15 7:45
mvaPaulo Zemek2-Mar-15 7:45 
GeneralRe: StreamReader in TcpListener Pin
Member 114922552-Mar-15 8:25
Member 114922552-Mar-15 8:25 
QuestionDatagridview row replay Pin
sdfsdfsdfewrew3feff1-Mar-15 5:03
sdfsdfsdfewrew3feff1-Mar-15 5:03 
GeneralRe: Datagridview row replay Pin
Richard MacCutchan1-Mar-15 6:15
mveRichard MacCutchan1-Mar-15 6:15 
GeneralRe: Datagridview row replay Pin
sdfsdfsdfewrew3feff1-Mar-15 8:23
sdfsdfsdfewrew3feff1-Mar-15 8:23 
GeneralRe: Datagridview row replay Pin
Richard MacCutchan1-Mar-15 22:38
mveRichard MacCutchan1-Mar-15 22:38 
GeneralRe: Datagridview row replay Pin
Eddy Vluggen2-Mar-15 8:02
professionalEddy Vluggen2-Mar-15 8:02 
Questioncreating a generic factory class that handles ValueTypes ? Pin
BillWoodruff28-Feb-15 23:36
professionalBillWoodruff28-Feb-15 23:36 
AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
OriginalGriff1-Mar-15 0:11
mveOriginalGriff1-Mar-15 0:11 
GeneralRe: creating a generic factory class that handles ValueTypes ? Pin
BillWoodruff1-Mar-15 1:23
professionalBillWoodruff1-Mar-15 1:23 
AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
manchanx1-Mar-15 1:53
professionalmanchanx1-Mar-15 1:53 
GeneralRe: creating a generic factory class that handles ValueTypes ? Pin
BillWoodruff1-Mar-15 6:26
professionalBillWoodruff1-Mar-15 6:26 
AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
Richard Deeming2-Mar-15 2:24
mveRichard Deeming2-Mar-15 2:24 
QuestionIs there a way to make "speakers" pickup 440hz? Pin
Member 1148826328-Feb-15 18:13
Member 1148826328-Feb-15 18:13 
AnswerRe: Is there a way to make "speakers" pickup 440hz? Pin
OriginalGriff28-Feb-15 20:05
mveOriginalGriff28-Feb-15 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.