winforms - how to export and save a file fetching name from database and contains "/" in its name c# -


i have winforms application.in application exporting text file local machine , path coming database "c:\myfiles".

now problem exporting such file has "/" (forward slash) in between name "abc/def/testing". when exporting file local machine giving error "c:\\myfiles\\abc/def/testing.text" not exist or check specified path exist.

i stuck in problem.any appreciated.thanks in advance.

you can't. filenames can;t have forward slashes in them. replace them character underscore (_):

filename = filename.replace("/","_"); 

or replace all invalid characters:

string invalidchars = new string(path.getinvalidfilenamechars());  foreach (char c in invalidchars) {     filename = filename.replace(c.tostring(), "");  } 

from msdn:

use character in current code page name, including unicode characters , characters in extended character set (128–255), except following:

  • the following reserved characters:
     < (less than)      > (greater than)      : (colon)      " (double quote)      / (forward slash)      \ (backslash)      | (vertical bar or pipe)      ? (question mark)      * (asterisk) 
  • integer value zero, referred ascii nul character.
  • characters integer representations in range 1 through 31, except alternate data streams these characters allowed. more information file streams, see file streams.
  • any other character target file system not allow.

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -