Solved

C# console application question need help with public string Main

Posted on 2007-08-03
4
496 Views
Last Modified: 2013-11-07
How would I add the fileupload to the public static main to be able to run this console application



using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.Security.Cryptography.X509Certificates;

using System.IO;

namespace simpleDTpost

{

class httpPost

{

public static void Main(string[] args)

{

}

static void FileUpload()

{

string dataBoundary = "------------------------------7d2e2c76e104be--";

CookieContainer cookies = new CookieContainer();

string uri = ("https://www.qa.dealertrack.com/DealerFeed/Dealerfileupload.asp");

string filename = (@"Z:\ZQ1412JPM\dealers.csv");

string user = "xxxxxx";

string passwd = "xxxxxx";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

req.Credentials = new NetworkCredential(user, passwd);

req.CookieContainer = cookies;

X509Certificate x509 = X509Certificate.CreateFromCertFile(@"C:\Documents and Settings\rbreault\Desktop\qa.dt.cer");

req.ClientCertificates.Add(x509);

req.ContentType = "multipart/form-data; boundary=---------------------------7d2e2c76e104be Accept-Encoding: gzip, deflate -----------------------------7d2e2c76e104be";

req.Method = "POST";

byte[] fileData = File.ReadAllBytes(filename);

string fileStr = Convert.ToBase64String(fileData);

StringBuilder dataString = new StringBuilder();

StringBuilder dataString2 = new StringBuilder();

dataString.Append(dataBoundary + "\r\n");

dataString.Append("Content-Disposition: form-data; name=\"FILE\"; filename=\"file.csv\"\r\n");

dataString.Append("Content-Type: Application/octet-stream\r\n\r\n");

byte[] tmpPostData = System.Text.Encoding.Default.GetBytes(dataString.ToString());

byte[] t = new byte[tmpPostData.Length + fileData.Length];

tmpPostData.CopyTo(t, 0);

fileData.CopyTo(t,tmpPostData.Length);

string tmp = System.Text.Encoding.Default.GetString(t);

req.ContentLength = t.Length;

Stream tempStream = req.GetRequestStream();

// Write the data to be posted to the request stream

tempStream.Write(t, 0, t.Length);

tempStream.Close();

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Read the raw HTML from the request

StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.Default);

// Convert the stream to a string

string s = sr.ReadToEnd();

sr.Close();

resp.Close();

Console.WriteLine(s);


}

}

}





Thanks in advance
0
Comment
Question by:jareddraper
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 19626508
I don't understand your problem:

public static void Main(string[] args)
{
   FileUpload();
}

Bob
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 19626556
Hi jareddraper;

Hope that this is what you are looking for.

public static void Main(string[] args)
{

    FileUpload();
    // So that the Console window does not go away after the function is run
    // place a console readline to stop the program from terminating.
    Console.Readline();

}

Fernando
0
 

Author Comment

by:jareddraper
ID: 19626645
Thank you so much sorry for the dumb question.... I am going to split the points since you both answered the question but FernandoSoto added a extra line for me. I am trying to be fair hope that doesn't bother either of you.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 19628375
Not a problem, Always glad to help. ;=)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now