Results 1 to 12 of 12

Thread: Problem using WriteFile with files stored on other servers?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    122

    Question Problem using WriteFile with files stored on other servers?

    I have an ASP.NET site in which I need to binary-write the contents of files to the users' browsers rather than linking to the files via the use of URLs. The following example shows how to open a file on a local drive using its physical path and then write the binary contents of the file to the browser:

    <VBCODE>

    Response.ContentType = "Application/pdf"
    Response.WriteFile("C:\Test\Test.pdf")
    Response.End()

    </VBCODE>

    The above code works fine, but if I put the file on a mapped drive (e.g. "G:\Test\Test.pdf"), I get an error which says "System.IO.DirectoryNotFoundException: Could not find a part of the path "G:\Test\Test.pdf".

    If I use the full path to the file, which is on another server (e.g. "\\ServerName\cdrive\Test\Test.pdf"), I get the following error message: "System.IO.IOException: Logon failure: unknown user name or bad password"

    I am able to access the file via Windows Explorer. I believe the problem may have something to do with authentication. Can anyone help me with this?

    Thanks.

  2. #2
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    I am having the same problem...

    Does nobody have an answer for this?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Problem using WriteFile with files stored on other servers?

    Show your code so that I can see what you're doing.

  4. #4
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    I'm just trying to copy a file from a network location to my web server directory:
    VB Code:
    1. FileCopy(strSourcePath, Server.MapPath(strFileName))
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Problem using WriteFile with files stored on other servers?

    Either give the asp.net worker process permissions on that folder (Give Everyone permissions on that shared folder) or set impersonation on your application. Unless your security model does not go along those lines.

    If that's not what you're looking for, I have seen another method to accomplish the same thing floating around, I can dig it up for you.

  6. #6
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    The problem is that the ASPNET user is not a domain user and so can't access the network. In addition, when deployed, the directory I need to access might not even be in the same domain.

    I need some way of (ideally) logging onto the required domain, copying the file, and logging back out again.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Problem using WriteFile with files stored on other servers?


  8. #8
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    Thanks...but my project is in VB and I don't know how to covert that code...

    There's a link at the bottom of that page on an alternative method:

    Accessing Shared Folders in ASP.NET

    ...But again it's in C
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Problem using WriteFile with files stored on other servers?

    It's really really easy converting C# to VB.NET and vice versa!

    I usually do it manually but you can try this:
    http://www.developerfusion.co.uk/uti...sharptovb.aspx

  10. #10
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    Hmmm....That utility fails to convert either code snippets...

    EDIT: Actually, I've realised that both those code samples contain unmanaged code...which if my memory serves me correctly, can't be implemented in VB.NET?
    Last edited by simonm; May 5th, 2006 at 10:03 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Problem using WriteFile with files stored on other servers?

    Unmanaged code can be implemented in VB.NET, as it has been in C#. What parts are you having trouble with? (Do it in parts)

  12. #12
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Problem using WriteFile with files stored on other servers?

    Well, the code converter took issue with the key word Extern. Here is an example:
    Code:
     //WIN32API - WNetCancelConnection2
     [DllImport("mpr.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
     private static extern int WNetCancelConnection2A (
      [MarshalAs (UnmanagedType.LPStr)]
      string lpName,
      int dwFlags,
      int fForce
      );
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width