Solved

C# console application question need help with public string Main

Posted on 2007-08-03
4
501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 63

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 63

Expert Comment

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

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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