Showing posts with label hit. Show all posts
Showing posts with label hit. Show all posts

Wednesday, March 28, 2012

System.IO.FileNotFoundException using file.copy

I had previously posted this on the security ng, but haven't had a hit so I
was wondering if someone here would be willing to take a stab. I am trying
to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity
=CType(User.Identity,System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
dim Temp as string="TestFile"
File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
impersonationContext.Undo()
I get the error "System.IO.FileNotFoundException: Could not find file
\\Server\File..." when running it from the [authenticated] client browse
r.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.
Any help is appreciated.
P.S. The web server is a backup domain w2k controller also, and the asp.net
user had to be changed to IWAM_Machine.to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test -
it should work because the principal will be a primary token, if not, turn
off anonymous.
to get around this, your code will need to logon as a domain account with
enough permission to do the copy.
-- bruce (sqlwork.com)
"Stephen Witter" <switter@.enpathmed.com> wrote in message
news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> I had previously posted this on the security ng, but haven't had a hit so
I
> was wondering if someone here would be willing to take a stab. I am
trying
> to copy a file to a network drive. I can do it on the web server but not
> from a client. Here is the code:
> Dim impersonationContext As
> System.Security.Principal.WindowsImpersonationContext
> Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity
> currentWindowsIdentity
> =CType(User.Identity,System.Security.Principal.WindowsIdentity)
> impersonationContext = currentWindowsIdentity.Impersonate()
> dim Temp as string="TestFile"
> File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> impersonationContext.Undo()
> I get the error "System.IO.FileNotFoundException: Could not find file
> \\Server\File..." when running it from the [authenticated] client brow
ser.
> I searched everywhere on the web and MSDN on this error but found nothing.
> The error it occurs on the file copy statement The file.copy statement is
> trying to copy a file on a different server than the web server.
> Any help is appreciated.
> P.S. The web server is a backup domain w2k controller also, and the
asp.net
> user had to be changed to IWAM_Machine.
>
The funny thing is I have tried to run the process from every server, even
the one where the file resides (and where it is being copied to), and they
all give the same message, that is, that the file does not exist. The only
place it works is on the web server. Anonymous access is turn off on the web
site.
I added the following code to test it:
Dim FilePermission As New FileIOPermission(FileIOPermissionAccess.AllAccess,
" \\MyServer\MyShare\SomeDirectory\Templat
e.doc") FilePermission.Assert()
If System.IO.File.Exists(" \\MyServer\MyShare\SomeDirectory\Templat
e.doc")
then
response.write("OK User: ") response.write(User.Identity.Name)
response.end
Else
Try
FilePermission.Demand()
response.write("Exists But Access Denied , User: ")
response.write(User.Identity.Name)
Catch se As Exception
response.write("Realy doesn't exist")
End Try
End If
It always returns "Exists But Access Denied , User: DOMAIN\User"
Thanks for your reply though. I know these situations can be caused by alot
of different factors.
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:u3sAi2OREHA.2716@.tk2msftngp13.phx.gbl...
> to copy to another server you need to impersonate a primary token, not an
> impersonation. to quickly test this, on the actual server, run ie and
test -
> it should work because the principal will be a primary token, if not, turn
> off anonymous.
> to get around this, your code will need to logon as a domain account with
> enough permission to do the copy.
> -- bruce (sqlwork.com)
> "Stephen Witter" <switter@.enpathmed.com> wrote in message
> news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
so
> I
> trying
not
> System.Security.Principal.WindowsIdentity
browser.
nothing.
is
> asp.net
>

System.IO.FileNotFoundException using file.copy

I had previously posted this on the security ng, but haven't had a hit so I
was wondering if someone here would be willing to take a stab. I am trying
to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:

Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity
=CType(User.Identity,System.Security.Principal.Win dowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
dim Temp as string="TestFile"
File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")

impersonationContext.Undo()

I get the error "System.IO.FileNotFoundException: Could not find file
\\Server\File..." when running it from the [authenticated] client browser.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.

Any help is appreciated.

P.S. The web server is a backup domain w2k controller also, and the asp.net
user had to be changed to IWAM_Machine.to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test -
it should work because the principal will be a primary token, if not, turn
off anonymous.

to get around this, your code will need to logon as a domain account with
enough permission to do the copy.

-- bruce (sqlwork.com)

"Stephen Witter" <switter@.enpathmed.com> wrote in message
news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> I had previously posted this on the security ng, but haven't had a hit so
I
> was wondering if someone here would be willing to take a stab. I am
trying
> to copy a file to a network drive. I can do it on the web server but not
> from a client. Here is the code:
> Dim impersonationContext As
> System.Security.Principal.WindowsImpersonationCont ext
> Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity
> currentWindowsIdentity
> =CType(User.Identity,System.Security.Principal.Win dowsIdentity)
> impersonationContext = currentWindowsIdentity.Impersonate()
> dim Temp as string="TestFile"
> File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> impersonationContext.Undo()
> I get the error "System.IO.FileNotFoundException: Could not find file
> \\Server\File..." when running it from the [authenticated] client browser.
> I searched everywhere on the web and MSDN on this error but found nothing.
> The error it occurs on the file copy statement The file.copy statement is
> trying to copy a file on a different server than the web server.
> Any help is appreciated.
> P.S. The web server is a backup domain w2k controller also, and the
asp.net
> user had to be changed to IWAM_Machine.
The funny thing is I have tried to run the process from every server, even
the one where the file resides (and where it is being copied to), and they
all give the same message, that is, that the file does not exist. The only
place it works is on the web server. Anonymous access is turn off on the web
site.

I added the following code to test it:

Dim FilePermission As New FileIOPermission(FileIOPermissionAccess.AllAccess,
"\\MyServer\MyShare\SomeDirectory\Template.doc") FilePermission.Assert()
If System.IO.File.Exists("\\MyServer\MyShare\SomeDirectory\Template.doc")
then
response.write("OK User: ") response.write(User.Identity.Name)
response.end
Else
Try
FilePermission.Demand()
response.write("Exists But Access Denied , User: ")
response.write(User.Identity.Name)
Catch se As Exception
response.write("Realy doesn't exist")
End Try
End If

It always returns "Exists But Access Denied , User: DOMAIN\User"

Thanks for your reply though. I know these situations can be caused by alot
of different factors.

"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:u3sAi2OREHA.2716@.tk2msftngp13.phx.gbl...
> to copy to another server you need to impersonate a primary token, not an
> impersonation. to quickly test this, on the actual server, run ie and
test -
> it should work because the principal will be a primary token, if not, turn
> off anonymous.
> to get around this, your code will need to logon as a domain account with
> enough permission to do the copy.
> -- bruce (sqlwork.com)
> "Stephen Witter" <switter@.enpathmed.com> wrote in message
> news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> > I had previously posted this on the security ng, but haven't had a hit
so
> I
> > was wondering if someone here would be willing to take a stab. I am
> trying
> > to copy a file to a network drive. I can do it on the web server but
not
> > from a client. Here is the code:
> > Dim impersonationContext As
> > System.Security.Principal.WindowsImpersonationCont ext
> > Dim currentWindowsIdentity As
> System.Security.Principal.WindowsIdentity
> > currentWindowsIdentity
> > =CType(User.Identity,System.Security.Principal.Win dowsIdentity)
> > impersonationContext = currentWindowsIdentity.Impersonate()
> > dim Temp as string="TestFile"
> > File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> > impersonationContext.Undo()
> > I get the error "System.IO.FileNotFoundException: Could not find file
> > \\Server\File..." when running it from the [authenticated] client
browser.
> > I searched everywhere on the web and MSDN on this error but found
nothing.
> > The error it occurs on the file copy statement The file.copy statement
is
> > trying to copy a file on a different server than the web server.
> > Any help is appreciated.
> > P.S. The web server is a backup domain w2k controller also, and the
> asp.net
> > user had to be changed to IWAM_Machine.

System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

System.IO.IOException: The filename, directory name, or volume label
syntax is incorrect.

I have hit a problem for which I can find no solutions. Has anyone any
ideas?

I am writing XML into a Memory STream and using a Transform to make
HTML. This works fine normally, but I have no the above stated error.

I did get some odd chars in the HTML name which caused a problem,
which I corrected. The current error seems to random. I am wondering
if memory is the problem, or disk space.

Last Trace - html 2-->../Grohe/Grohe-Sundries-Handles-Handles-Automatic-2000-47255000.html<--
shows the filename

Code:

string HTMLName = xmlName;

Trace.Warn ("html--" + HTMLName);

string thisManNameDir = thisManName;
thisManNameDir = thisManNameDir.Replace(" ","");

HTMLName = "../" + thisManNameDir + "/" + HTMLName;
Trace.Warn ("html 2-->" + HTMLName + "<--");
//Trace.Warn("writing html" + HTMLName );
XmlUrlResolver resolver = new XmlUrlResolver();

string thisURL1 = Request.Url.ToString();
Trace.Warn("header " + thisURL1);
thisURL1 = thisURL1.Replace("/myxml/Xml1.aspx","");
string thisURL = thisURL1.Replace("http://","");

thisURL1 = thisURL1.Replace(".co.uk","");
thisURL1 = thisURL1.Replace(".com","");
thisURL1 = thisURL1.Replace(".biz","");

thisURL1 = thisURL1.Replace("http://www.","");
string thisDomain = thisURL1.Replace("http://","");

NetworkCredential cred = new
NetworkCredential(thisDomain,"pwd",thisURL);

thisStream.Position = 0;
Trace.Warn("a");
//XmlTextReader myTxtReader = new XmlTextReader (thisStream);

Trace.Warn("a1");
string xslPath = Server.MapPath("myXSL.xsl");
Trace.Warn("a2");
string htmlPath = Server.MapPath(HTMLName);
Trace.Warn("a3");
XPathDocument aXPathDocument = new XPathDocument(thisStream);
Trace.Warn("a4");
XslTransform transform = new XslTransform();
Trace.Warn("a5");
transform.Load(xslPath, resolver);

StreamWriter aStreamWriter = new StreamWriter(htmlPath);

Trace.Warn("a6");

transform.Transform(aXPathDocument,null,aStreamWri ter, resolver);

aStreamWriter.Flush();
aStreamWriter.Close();

Trace.Warn("a7");
//Trace.Warn("ending html");

}I solved this.

"Trevor" <sales@.logicians.com> wrote in message
news:88a9861a.0407260251.53f2d587@.posting.google.c om...
> System.IO.IOException: The filename, directory name, or volume label
> syntax is incorrect.
>
> I have hit a problem for which I can find no solutions. Has anyone any
> ideas?
> I am writing XML into a Memory STream and using a Transform to make
> HTML. This works fine normally, but I have no the above stated error.
> I did get some odd chars in the HTML name which caused a problem,
> which I corrected. The current error seems to random. I am wondering
> if memory is the problem, or disk space.
> Last Trace - html
2-->../Grohe/Grohe-Sundries-Handles-Handles-Automatic-2000-47255000.html<--
> shows the filename
> Code:
> string HTMLName = xmlName;
> Trace.Warn ("html--" + HTMLName);
>
> string thisManNameDir = thisManName;
> thisManNameDir = thisManNameDir.Replace(" ","");
> HTMLName = "../" + thisManNameDir + "/" + HTMLName;
> Trace.Warn ("html 2-->" + HTMLName + "<--");
> //Trace.Warn("writing html" + HTMLName );
> XmlUrlResolver resolver = new XmlUrlResolver();
>
> string thisURL1 = Request.Url.ToString();
> Trace.Warn("header " + thisURL1);
> thisURL1 = thisURL1.Replace("/myxml/Xml1.aspx","");
> string thisURL = thisURL1.Replace("http://","");
> thisURL1 = thisURL1.Replace(".co.uk","");
> thisURL1 = thisURL1.Replace(".com","");
> thisURL1 = thisURL1.Replace(".biz","");
> thisURL1 = thisURL1.Replace("http://www.","");
> string thisDomain = thisURL1.Replace("http://","");
> NetworkCredential cred = new
> NetworkCredential(thisDomain,"pwd",thisURL);
>
> thisStream.Position = 0;
> Trace.Warn("a");
> //XmlTextReader myTxtReader = new XmlTextReader (thisStream);
>
> Trace.Warn("a1");
> string xslPath = Server.MapPath("myXSL.xsl");
> Trace.Warn("a2");
> string htmlPath = Server.MapPath(HTMLName);
> Trace.Warn("a3");
> XPathDocument aXPathDocument = new XPathDocument(thisStream);
> Trace.Warn("a4");
> XslTransform transform = new XslTransform();
> Trace.Warn("a5");
> transform.Load(xslPath, resolver);
> StreamWriter aStreamWriter = new StreamWriter(htmlPath);
> Trace.Warn("a6");
>
> transform.Transform(aXPathDocument,null,aStreamWri ter, resolver);
> aStreamWriter.Flush();
> aStreamWriter.Close();
>
>
> Trace.Warn("a7");
> //Trace.Warn("ending html");
> }
Hello. I know it's been almost 3 years since this post, but I'm experiencing the same problem that you had and you're the only person who seems to have an idea on how to fix it. Do you remember what your problem was and how you resolved it?

Thanks in advance.

From http://www.developmentnow.com/g/8_2...-incorrect-.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
"IIT Guy" <nospam@.developmentnow.comwrote in message
news:c2456389-6c48-41fc-b787-4447eefa6d17@.developmentnow.com...

Quote:

Originally Posted by

Hello. I know it's been almost 3 years since this post, but I'm
experiencing the same problem that you had and you're the only person who
seems to have an idea on how to fix it. Do you remember what your problem
was and how you resolved it?
>

The '..' characters are not allowed.

System.IO.IOException: The filename, directory name, or volume label syntax is incorr

System.IO.IOException: The filename, directory name, or volume label
syntax is incorrect.
I have hit a problem for which I can find no solutions. Has anyone any
ideas?
I am writing XML into a Memory STream and using a Transform to make
HTML. This works fine normally, but I have no the above stated error.
I did get some odd chars in the HTML name which caused a problem,
which I corrected. The current error seems to random. I am wondering
if memory is the problem, or disk space.
Last Trace - html 2-->../Grohe/Grohe-Sundries-Handles-Handles-Automatic-2000
-47255000.html<--
shows the filename
Code:
string HTMLName = xmlName;
Trace.Warn ("html--" + HTMLName);
string thisManNameDir = thisManName;
thisManNameDir = thisManNameDir.Replace(" ","");
HTMLName = "../" + thisManNameDir + "/" + HTMLName;
Trace.Warn ("html 2-->" + HTMLName + "<--");
//Trace.Warn("writing html" + HTMLName );
XmlUrlResolver resolver = new XmlUrlResolver();
string thisURL1 = Request.Url.ToString();
Trace.Warn("header " + thisURL1);
thisURL1 = thisURL1.Replace("/myxml/Xml1.aspx","");
string thisURL = thisURL1.Replace("http://","");
thisURL1 = thisURL1.Replace(".co.uk","");
thisURL1 = thisURL1.Replace(".com","");
thisURL1 = thisURL1.Replace(".biz","");
thisURL1 = thisURL1.Replace("http://www.","");
string thisDomain = thisURL1.Replace("http://","");
NetworkCredential cred = new
NetworkCredential(thisDomain,"pwd",thisURL);
thisStream.Position = 0;
Trace.Warn("a");
//XmlTextReader myTxtReader = new XmlTextReader (thisStream);
Trace.Warn("a1");
string xslPath = Server.MapPath("myXSL.xsl");
Trace.Warn("a2");
string htmlPath = Server.MapPath(HTMLName);
Trace.Warn("a3");
XPathDocument aXPathDocument = new XPathDocument(thisStream);
Trace.Warn("a4");
XslTransform transform = new XslTransform();
Trace.Warn("a5");
transform.Load(xslPath, resolver);
StreamWriter aStreamWriter = new StreamWriter(htmlPath);
Trace.Warn("a6");
transform. Transform(aXPathDocument,null,aStreamWri
ter, resolver);
aStreamWriter.Flush();
aStreamWriter.Close();
Trace.Warn("a7");
//Trace.Warn("ending html");
}I solved this.
"Trevor" <sales@.logicians.com> wrote in message
news:88a9861a.0407260251.53f2d587@.posting.google.com...
> System.IO.IOException: The filename, directory name, or volume label
> syntax is incorrect.
>
> I have hit a problem for which I can find no solutions. Has anyone any
> ideas?
> I am writing XML into a Memory STream and using a Transform to make
> HTML. This works fine normally, but I have no the above stated error.
> I did get some odd chars in the HTML name which caused a problem,
> which I corrected. The current error seems to random. I am wondering
> if memory is the problem, or disk space.
> Last Trace - html
2-->../Grohe/Grohe-Sundries-Handles-Handles-Automatic-2000-47255000.html<--
> shows the filename
> Code:
> string HTMLName = xmlName;
> Trace.Warn ("html--" + HTMLName);
>
> string thisManNameDir = thisManName;
> thisManNameDir = thisManNameDir.Replace(" ","");
> HTMLName = "../" + thisManNameDir + "/" + HTMLName;
> Trace.Warn ("html 2-->" + HTMLName + "<--");
> //Trace.Warn("writing html" + HTMLName );
> XmlUrlResolver resolver = new XmlUrlResolver();
>
> string thisURL1 = Request.Url.ToString();
> Trace.Warn("header " + thisURL1);
> thisURL1 = thisURL1.Replace("/myxml/Xml1.aspx","");
> string thisURL = thisURL1.Replace("http://","");
> thisURL1 = thisURL1.Replace(".co.uk","");
> thisURL1 = thisURL1.Replace(".com","");
> thisURL1 = thisURL1.Replace(".biz","");
> thisURL1 = thisURL1.Replace("http://www.","");
> string thisDomain = thisURL1.Replace("http://","");
> NetworkCredential cred = new
> NetworkCredential(thisDomain,"pwd",thisURL);
>
> thisStream.Position = 0;
> Trace.Warn("a");
> //XmlTextReader myTxtReader = new XmlTextReader (thisStream);
>
> Trace.Warn("a1");
> string xslPath = Server.MapPath("myXSL.xsl");
> Trace.Warn("a2");
> string htmlPath = Server.MapPath(HTMLName);
> Trace.Warn("a3");
> XPathDocument aXPathDocument = new XPathDocument(thisStream);
> Trace.Warn("a4");
> XslTransform transform = new XslTransform();
> Trace.Warn("a5");
> transform.Load(xslPath, resolver);
> StreamWriter aStreamWriter = new StreamWriter(htmlPath);
> Trace.Warn("a6");
>
> transform. Transform(aXPathDocument,null,aStreamWri
ter, resolver);
> aStreamWriter.Flush();
> aStreamWriter.Close();
>
>
> Trace.Warn("a7");
> //Trace.Warn("ending html");
> }