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 3226820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:30:07+00:00 2026-05-17T16:30:07+00:00

Doing a file upload to an aspx page from C#. Getting a: PathTooLongException The

  • 0

Doing a file upload to an aspx page from C#. Getting a:

PathTooLongException
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Here’s the code:

            try
            {
                using (var client = new WebClient())
                {
                    String url =
                        String.Format(
                            "http//localhost:49536/ManualUploadTest.aspx?key={0}&name={1}&address={2}&phone={3}&email={4}&node={5}",
                            "changeme",
                            "john",
                            "10 Downing Street",
                            "555 555 6165",
                            "test@yahoo.com",
                            "TestNode");

                    var len = url.Length;  // this length is 146 
                    var encodeLen = HttpUtility.UrlEncode(url).Length; // this length is 180

                    //client.BaseAddress = "http//localhost:49536";

                    byte[] result = client.UploadFile(HttpUtility.UrlEncode(url), path);

                    // throws exception during UploadFile
                    // ... more code here

The url string looks like this:

http//localhost:49536/ManualUploadTest.aspx?key=changeme&name=john&address=10 Downing Street&phone=555 555 6165&email=test@yahoo.com&node=TestNode

The path is:

Y:\\10mb.zip

Thanks for any help!

  • 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-05-17T16:30:07+00:00Added an answer on May 17, 2026 at 4:30 pm

    Try fixing the URL: http://... instead of http//...; also, I’d use the Uri class and not UrlEncode().

    Uri url = new Uri(String.Format("http://localhost:49536/ManualUploadTest.aspx?key={0}&name={1}&address={2}&phone={3}&email={4}&node={5}",
                                    HttpUtility.UrlEncode("changeme"),
                                    HttpUtility.UrlEncode("john"),
                                    HttpUtility.UrlEncode("10 Downing Street"),
                                    HttpUtility.UrlEncode("555 555 6165"),
                                    HttpUtility.UrlEncode("test@yahoo.com"),
                                    HttpUtility.UrlEncode("TestNode")));
    byte[] result = client.UploadFile(url, path);
    

    Edit: I tracked down the reason for exception… if you supply a string, it tries to create a Uri internally (which fails because of the malformed protocol http//), then it tries to get the full path for the Uri using Path.GetFullPath(url), and this then fails with the PathTooLongException.

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

Sidebar

Related Questions

I'm doing something really simple: slurping an entire text file from disk into a
K... I'm doing something obviously wrong. I have a simple page with a file
im trying to use a file upload control from the obout control library, i
I am doing file-upload for a web-application (running on unix/linux). I'm wondering if there
I am trying to upload file to a php server from my android device.
I have a Windows C++ program that is doing something like: FILE* pf =
I'm trying to figure out what a Java applet's class file is doing under
I'm used to doing all my coding in one C file. However, I'm working
I'm probably doing this all wrong. I have a text file full of data
any problems with doing this? int i = new StreamReader(file.txt).ReadToEnd().Split(new char[] {'\n'}).Length

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.