×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

filestream 'could nor find a part of the path'

filestream 'could nor find a part of the path'

filestream 'could nor find a part of the path'

(OP)
I searched all afternoon - found lots of post here and there ... but error still here ...
I am trying to open a file (to store it in a database).
The error occurs here
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
If I run it on my machine (local), and try
to open a file
* c:\Project\MyFile.pdf
=> it works fine
* C:\Users\ME\Desktop\MyFile.pdf
=> access denied
If I run it from the web , I get the error
=> could nor find a part of the path

* In Web.config I have added : <identity impersonate = "true"></identity>
* Users will upload the files they want, I cannot ask them to change the files access right (I am not sure they have the rights to do it !)
* on the server, IIS V6.0 , Application Pools Identity is 'Network Services', I checked "Enable anonymous access" and "Integrated Windows authentication" on th Web Site.
* I am using Visual Studion 2008

If you need more information to help me out - just ask !!!
Thanks

RE: filestream 'could nor find a part of the path'


* C:\Users\ME\Desktop\MyFile.pdf
because this is on your desktop, the location is by default secure to all accounts that are not you.
You will need to make sure you have EXPLICITLY given permission to the account that your webapp is running under (app pool of the specific website/app)

RE: filestream 'could nor find a part of the path'

Quote (cbsm)

* Users will upload the files they want, I cannot ask them to change the files access right (I am not sure they have the rights to do it !)

Are you trying to make an upload form then?

http://msdn.microsoft.com/en-us/library/aa479405.a...


ASP.NET appears to have a file upload form control. Taken from the MSDN:

CODE

<%@ Page Language="C#" %>

<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("C:\\Uploads\\" + 
                     FileUpload1.FileName);
                Label1.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Upload Files</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" /><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
         Text="Upload File" /> <br />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label></div>
    </form>
</body>
</html> 

RE: filestream 'could nor find a part of the path'

(OP)
I used something like you suggested Moregelen.
FileUpload fileUpload = (FileUpload)controlCell;
HttpPostedFile myFile = fileUpload.PostedFile;
int nFileLen = myFile.ContentLength;
byte[] myData = new byte[nFileLen];
myFile.InputStream.Read(myData, 0, nFileLen);


But I still doesn't understand why the previous code did not work.
( OK for the rights issue for files in 'myDocuments' - but when I run the app on the web, I get an error on any files ...)
I suppose the most important is that I managed to do what I needed to ...
Thank you for taking the time to answer me !

RE: filestream 'could nor find a part of the path'

The reason you got an error is that you need to remember that this code is running on the server as the server. It has absolutely no access to the connecting machines files unless the user explicitly gives access (either through trippy ActiveX mechanisms or through a file upload). Even if you are running the website locally, the IIS service still will only have access to its own folders; it doesn't get to run wild on your system.

Just remember.. while this is written like a program, ALL of the processing happens on the server end. By the time it reaches the client, it isn't anything more than an HTML page.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close