Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# console application question need help with public string Main

Posted on 2007-08-03
4
Medium Priority
?
505 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 1000 total points
ID: 19626508
I don't understand your problem:

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

Bob
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1000 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 64

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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