wimthepimscake
asked on
Create file with path longer than MAX_LENGTH > 260 chars
I have a problem with writing a file that exceeds the max_length supported by kernel32 funtion CreateFile.
I have managed to write the directory path using this code:
[DllImport("kernel32.dll", EntryPoint="CreateDirector yW", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true)]
private static extern int CreateDirectoryW (string lpPathName, int lpSecurityAttributes);
private void CreateDirectoryUnicode(str ing path)
{
string [] pathparts = path.Split('\\');
string currentPart = pathparts[0]+"\\"+pathpart s[1];
int result = CreateDirectoryW(currentPa rt,0);
for (int i=2; i<pathparts.Length; i++)
{
currentPart += "\\"+pathparts[i];
CreateDirectoryW(currentPa rt,0);
}
}
The question is now, how do I write a file to that path, because my next coide failes because the path is too long:
objStreamWriter = new StreamWriter(CacheDirector y + @"\" +
htmldoc.ID.ToString() + ".htm", false, System.Text.Encoding.GetEn coding(htm ldoc.Encod ing));
objStreamWriter.Write(html doc.Text);
objStreamWriter.Close();
Can someone help me?
Wim
I have managed to write the directory path using this code:
[DllImport("kernel32.dll",
private static extern int CreateDirectoryW (string lpPathName, int lpSecurityAttributes);
private void CreateDirectoryUnicode(str
{
string [] pathparts = path.Split('\\');
string currentPart = pathparts[0]+"\\"+pathpart
int result = CreateDirectoryW(currentPa
for (int i=2; i<pathparts.Length; i++)
{
currentPart += "\\"+pathparts[i];
CreateDirectoryW(currentPa
}
}
The question is now, how do I write a file to that path, because my next coide failes because the path is too long:
objStreamWriter = new StreamWriter(CacheDirector
htmldoc.ID.ToString() + ".htm", false, System.Text.Encoding.GetEn
objStreamWriter.Write(html
objStreamWriter.Close();
Can someone help me?
Wim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bob,
can you please show how this works, I already tried it but I was not able to get it functioning.
Wim
can you please show how this works, I already tried it but I was not able to get it functioning.
Wim
It was worth a shot. Did you try Alex's solution?
Bob
Bob
ASKER
Yep, I am using Alex's solution now. Thanx for the tips.
Wim
Wim
ASKER
Oke, I cheered to fast, the solution alex gave did not work either.
When I create a file using a streamwriter I am getting the same error.
Wim
When I create a file using a streamwriter I am getting the same error.
Wim
ASKER
Admin, please remove this solution, as it is not correct.
Wim
Wim
Bob