2

I'm passing values from a C# application to an ASP.NET MVC Web API that's been created. I've learned that when my value includes "\" like the the following:

{ id:"1", path:"D:\Backup\DataSource\MyFile.txt", name:"test" }

that the parameter in MyAction is null.

[HttpPost]
public CustomResponse MyAction(CustomEntity entity)
{
  ... // do stuff
}

public class CustomEntity
{
  public string id { get; set; }
  public string path { get; set; }
  public string name { get; set; }
}

If the path does NOT include "\" everything works as intended. I'm guessing this is some type of encoding issue. However, I'm not sure what kind of encoding I need to use before I send the values from my C# app to the Web API.

What kind of encoding do I need to use?

4
  • 1
    Try using double slashes. \\ instead of \. I think you need to escape the escape character. Commented Mar 12, 2013 at 20:32
  • I did that. But that's not my concern. I'm more concerned there are other characters that I need to consider that I'm not. That's why I'm asking about encoding. Commented Mar 12, 2013 at 20:59
  • Take a look at msdn.microsoft.com/en-us/library/windows/desktop/… for the actual list of rules about paths. In C# you can get an array of characters you would to escape file names at msdn.microsoft.com/en-us/library/… and paths at msdn.microsoft.com/en-us/library/…. Commented Mar 12, 2013 at 21:22
  • Check out this link - I think it might point you in the right direction. Commented Apr 24, 2013 at 20:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.