Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:53:23+00:00 2026-06-06T22:53:23+00:00

I m working on a console application that tries to download some files from

  • 0

I m working on a console application that tries to download some files from a website by logging in and then copying the files to a shared folder.

Here the domain I am working in is different that the domain of that shared folder where I need to save the files.

Currently I overcome this problem manually by opening the shared folder from the run and putting the username and password into the windows authentication dialog and then running the application.

Here is the code I m using –

 static public void Start()
        {
            try
            {
                serverpath = ConfigurationSettings.AppSettings["serverpath"];
                if (flag == 0)
                {
                    username = ConfigurationSettings.AppSettings["UserNameFN"];
                    password = ConfigurationSettings.AppSettings["PassWordFN"];
                }
                else
                {
                    username = ConfigurationSettings.AppSettings["UserNameMFS"];
                    password = ConfigurationSettings.AppSettings["PassWordMFS"];
                    check = true;
                }

                string webUrl = "https://www.website.org/";
                string formParams = string.Format("user={0}&password={1}", username, password);
                WebRequest req = WebRequest.Create(webUrl);
                req.ContentType = "application/x-www-form-urlencoded";
                req.Method = "POST";
                req.Proxy.Credentials = CredentialCache.DefaultCredentials;
                byte[] bytes = Encoding.ASCII.GetBytes(formParams);
                req.ContentLength = bytes.Length;
                using (Stream os = req.GetRequestStream())
                {
                    os.Write(bytes, 0, bytes.Length);
                }
                WebResponse resp = req.GetResponse();
                cookieHeader = resp.Headers["Set-cookie"];

             (ConfigurationSettings.AppSettings["UserNamePROD"], ConfigurationSettings.AppSettings["PassWordPROD"], ConfigurationSettings.AppSettings["DomainPROD"]);
                Directory.CreateDirectory(serverpath + @"Log\");
                Logging.Write_Line(DateTime.Now + " - File Transfer Started");
                if ((!check) || (count == 0))
                {
                  string[] filename = getFileNames.returnFileNames(cookieHeader)
                }
             }

With above code

Directory.CreateDirectory(serverpath + @"Log\"); this line throws an exception.

How can I programmatically login to the shared location while running my application from my machine?

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:53:25+00:00Added an answer on June 6, 2026 at 10:53 pm

    You might get away with it by executing the directory creation command as a shell process, like this (full namespaces provided in order to avoid cluttering up code with using directives):

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = 
        new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // Hides the command prompt window
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C mkdir " + serverpath + @"\Log";
    startInfo.Username = "domain\username";
    startInfo.Password = // SecureString object containing the password
    process.StartInfo = startInfo;
    process.Start();
    

    Not tested but logic suggests it might work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a console application that tries to download some files from a
Working with a Visual Basic.NET console application that features a VERY BASIC natural language
When working with a console application, a history of everything that has been entered
I have a Windows console application that returns some text. I want to read
I'm working in an mvc api and a console application with consume that as
I'm working on a test application that will run an mp4 file from internet.
I am working on a console application to insert data to a MS SQL
The following code is working great in a normal console application: private void button1_Click(object
I am working in the mysql console and trying to use a db that
I have a console project that I have been working on. I added log4net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.