Can't write to folder

R

Reggie

Hi And TIA. Running VS2005 and IIS7.0. I have a procedure that copies a
file to a folder in my web application. When I run the project from VS it
runs fine . I'm usin IE as default viewer. But when I type it directly into
IE (http://localhost/Menu.aspx) it bombs when I try to open the connection
cause the file doesn't get copied to the folder. Any thoughts/advice is
appreciated.

Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("WSMDDT_Old\MDB_Temp\" & strFile)
& ";" & _
"Extended Properties=""Excel 8.0;HDR=TRUE;IMEX=1"""

' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(xConnStr)
objXConn.Open()
 
G

Guest

Hi And TIA.  Running VS2005 and IIS7.0.  I have a procedure that copies a
file to a folder in my web application.  When I run the project from VS it
runs fine . I'm usin IE as default viewer.  But when I type it directly into
IE (http://localhost/Menu.aspx) it bombs when I try to open the connection
cause the file doesn't get copied to the folder.  Any thoughts/advice is
appreciated.

        Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & Server.MapPath("WSMDDT_Old\MDB_Temp\" & strFile)
& ";" & _
        "Extended Properties=""Excel 8.0;HDR=TRUE;IMEX=1"""

        ' create your excel connection object using the connection string
        Dim objXConn As New OleDbConnection(xConnStr)
        objXConn.Open()

When you run your code within VS you run it under your own user
account and this works. IIS uses a built-in group named IIS_IUSRS
(IUSR account) and it seems that this account has no rights on the
destination folder. Give to the IIS_USRS the write access to the
folder you want them to be able to write to. This can be done by
navigating to your folder in Windows Explorer, right-clicking on the
folder and selecting the Security Tab.
 
R

Reggie

IIS_IUSRS has all the permissions to write to the folder. Also, Network
Services and many others I have given full rights to (only to try and get it
to work), Nothing has worked yet. I'll keep trying.

--

Reggie
Hi And TIA. Running VS2005 and IIS7.0. I have a procedure that copies a
file to a folder in my web application. When I run the project from VS it
runs fine . I'm usin IE as default viewer. But when I type it directly
into
IE (http://localhost/Menu.aspx) it bombs when I try to open the connection
cause the file doesn't get copied to the folder. Any thoughts/advice is
appreciated.

Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("WSMDDT_Old\MDB_Temp\" & strFile)
& ";" & _
"Extended Properties=""Excel 8.0;HDR=TRUE;IMEX=1"""

' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(xConnStr)
objXConn.Open()

When you run your code within VS you run it under your own user
account and this works. IIS uses a built-in group named IIS_IUSRS
(IUSR account) and it seems that this account has no rights on the
destination folder. Give to the IIS_USRS the write access to the
folder you want them to be able to write to. This can be done by
navigating to your folder in Windows Explorer, right-clicking on the
folder and selecting the Security Tab.
 
G

Guest

IIS_IUSRS has all the permissions to write to the folder.  Also, Network
Services and many others I have given full rights to (only to try and get it
to work),  Nothing has worked yet.  I'll keep trying.


Maybe there is another problem then. Did you get an error about
insufficient write permissions, or the code is not working as
expected? if the latter is the case can you post the code? I don't see
anything what copies a file in the snippet you sent earlier
 
R

Reggie

Reggie
IIS_IUSRS has all the permissions to write to the folder. Also, Network
Services and many others I have given full rights to (only to try and get
it
to work), Nothing has worked yet. I'll keep trying.


Maybe there is another problem then. Did you get an error about
insufficient write permissions, or the code is not working as
expected? if the latter is the case can you post the code? I don't see
anything what copies a file in the snippet you sent earlier
Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("WSMDDT_Old\MDB_Temp\" &
strFile)
& ";" & _
"Extended Properties=""Excel 8.0;HDR=TRUE;IMEX=1"""

' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(xConnStr)
objXConn.Open()

No error message except stating that the file couldn't be found. Here's the
code. Everything runs fine when running from local except when I try to
copy a file to this folder.

'Import Excel file
If Not inpFileUpNIIN.PostedFile Is Nothing And
inpFileUpNIIN.PostedFile.ContentLength > 0 Then
strFileName =
System.IO.Path.GetFileName(inpFileUpNIIN.PostedFile.FileName)
strBaseDir = Server.MapPath("/MDB_Temp/")
Try
inpFileUpNIIN.PostedFile.SaveAs(strBaseDir & strFileName)
pathandfile = strBaseDir & strFileName
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
Exit Sub
End Try
Else
Response.Write("Please select a file to upload.")
Exit Sub
End If
 
R

Reggie

Reggie said:
Reggie



Maybe there is another problem then. Did you get an error about
insufficient write permissions, or the code is not working as
expected? if the latter is the case can you post the code? I don't see
anything what copies a file in the snippet you sent earlier


No error message except stating that the file couldn't be found. Here's
the code. Everything runs fine when running from local except when I try
to copy a file to this folder.

'Import Excel file
If Not inpFileUpNIIN.PostedFile Is Nothing And
inpFileUpNIIN.PostedFile.ContentLength > 0 Then
strFileName =
System.IO.Path.GetFileName(inpFileUpNIIN.PostedFile.FileName)
strBaseDir = Server.MapPath("/MDB_Temp/")
Try
inpFileUpNIIN.PostedFile.SaveAs(strBaseDir & strFileName)
pathandfile = strBaseDir & strFileName
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
Exit Sub
End Try
Else
Response.Write("Please select a file to upload.")
Exit Sub
End If

Got it somewhat figured out, but don't know why. If I run it using VS
server and use the setting Server.MapPath("/WSMDDT/MDB_Temp/") it says it
Could not find a part of the path
'C:\inetpub\wwwroot\WSMDDT\WSMDDT\MDB_Temp\ExcelImport_rep.xls'. If I us VS
and set it to Server.MapPath("/MDB_Temp/") it runs fine but then it doesn't
run when using the local server. I don't know why. I simply setup VS to
run it using IIS server with Server.MapPath("/WSMDDT/MDB_Temp/") and it now
runs except I can debug cause integrated windows authentication isn't
enabled. I'm using forms authentication and not sure how to setup so I can
debug.
 
D

David

To debug without running via studio, click Tools / Attach to Process.

Select the aspnet_wp process (hover over it first to ensure you are
debugging the correct version. On my machine, I have 1.1 and 2.0) I also
ensure in the attach to block that SQL Server is not selected. (Click the
select button to remove it).

Click Attach.

Debug as normal.

Personally, I prefer this way of handling it. I don't like the start button
starting up a browser and when you click stop, the browser closing again.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
R

Reggie

David Thanks for the reply. Did as you suggested but the aspnet_wp is not
in the list.
 
G

Guest

"Reggie" <[email protected]> wrote in message
Got it somewhat figured out, but don't know why.  If I run it using VS
server and use the setting Server.MapPath("/WSMDDT/MDB_Temp/") it says it
Could not find a part of the path
'C:\inetpub\wwwroot\WSMDDT\WSMDDT\MDB_Temp\ExcelImport_rep.xls'.

So, what path do you get when you call Server.MapPath("/") ? What
webserver do you use in VS (Project - Properties - Web) ?

I think the problem is in your configuration - your site is located in
C:\inetpub\wwwroot\WSMDDT, you call Server.MapPath("/WSMDDT/
MDB_Temp/") which is wrong, and you get an error. To see why it is not
working under http://localhost - remove Try..Catch..End. It should
show an error message after that.

Hope this helps.
 
D

David

If it isn't in the list when you try, then if you have not used your local
web for a while, it will have closed itself down. Simply open a browser and
goto your local site (ensure you call a .NET page, doesn't even need to be
in the same project) and that will start your aspnet_wp. (On different OS,
(vista I think) it could be called w3wp, on XP it is aspnet_wp).

Hope this helps.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
R

Reggie

David, Found it. (w3wp). Thanks!

--

Reggie
David said:
If it isn't in the list when you try, then if you have not used your local
web for a while, it will have closed itself down. Simply open a browser
and goto your local site (ensure you call a .NET page, doesn't even need
to be in the same project) and that will start your aspnet_wp. (On
different OS, (vista I think) it could be called w3wp, on XP it is
aspnet_wp).

Hope this helps.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
R

Reggie

gie
"Reggie" <[email protected]> wrote in message
Got it somewhat figured out, but don't know why. If I run it using VS
server and use the setting Server.MapPath("/WSMDDT/MDB_Temp/") it says it
Could not find a part of the path
'C:\inetpub\wwwroot\WSMDDT\WSMDDT\MDB_Temp\ExcelImport_rep.xls'.

So, what path do you get when you call Server.MapPath("/") ? What
webserver do you use in VS (Project - Properties - Web) ?

I think the problem is in your configuration - your site is located in
C:\inetpub\wwwroot\WSMDDT, you call Server.MapPath("/WSMDDT/
MDB_Temp/") which is wrong, and you get an error. To see why it is not
working under http://localhost - remove Try..Catch..End. It should
show an error message after that.

Hope this helps.

Using IIS 7.0 Server
Vista Business (SP1)
VS2005
..Net 2.0 (SP1)

Running using IIS Server

Server.MapPath("/") returns C:\inetpub\wwwroot\
Server.MapPath("/MDB_Temp/") returns C:\inetpub\wwwroot\MDB_Temp\
Server.MapPath("/WSMDDT/MDB_Temp/") returns
C:\inetpub\wwwroot\WSMDDT\MDB_Temp\

Running using VS Server

Server.MapPath("/") returns C:\inetpub\wwwroot\WSMDDT\
Server.MapPath("/MDB_Temp/") returns C:\inetpub\wwwroot\WSMDDT\MDB_Temp\
Server.MapPath("/WSMDDT/MDB_Temp/") returns
C:\inetpub\wwwroot\WSMDDT\WSMDDT\MDB_Temp\


The last one (running using IIS Server) is what I want and it is working as
expected. My problem was that when I originally posted my question I was
using VS server and the Server.MapPath("/WSMDDT/MDB_Temp/") failed, however
when I took out the WSMDDT portion so that it read
Server.MapPath("/MDB_Temp/") It ran fine from VS, but failed when I tried to
simply run the app from the local server. Think I'm good now cause I set it
up to run from IIS server and all is well. Just thought it was/is odd that
this happens. Thanks VERY much for all the help.
 
G

Guest

So, what path do you get when you call Server.MapPath("/") ? What
webserver do you use in VS (Project - Properties - Web) ?

I think the problem is in your configuration - your site is located in
C:\inetpub\wwwroot\WSMDDT, you call Server.MapPath("/WSMDDT/
MDB_Temp/") which is wrong, and you get an error. To see why it is not
working underhttp://localhost- remove Try..Catch..End. It should
show an error message after that.

Hope this helps.

Using IIS 7.0 Server
Vista Business (SP1)
VS2005
.Net 2.0 (SP1)

Running using IIS Server

Server.MapPath("/")  returns C:\inetpub\wwwroot\
Server.MapPath("/MDB_Temp/")  returns C:\inetpub\wwwroot\MDB_Temp\
Server.MapPath("/WSMDDT/MDB_Temp/")  returns
C:\inetpub\wwwroot\WSMDDT\MDB_Temp\

Running using VS Server

Server.MapPath("/")  returns C:\inetpub\wwwroot\WSMDDT\
Server.MapPath("/MDB_Temp/")  returns C:\inetpub\wwwroot\WSMDDT\MDB_Temp\
Server.MapPath("/WSMDDT/MDB_Temp/")  returns
C:\inetpub\wwwroot\WSMDDT\WSMDDT\MDB_Temp\

The last one (running using IIS Server) is what I want and it is working as
expected.  My problem was that when I originally posted my question I was
using VS server and the Server.MapPath("/WSMDDT/MDB_Temp/") failed, however
when I took out the WSMDDT portion so that it read
Server.MapPath("/MDB_Temp/") It ran fine from VS, but failed when I tried to
simply run the app from the local server.  Think I'm good now cause I set it
up to run from IIS server and all is well.  Just thought it was/is odd that
this happens.  Thanks VERY much for all the help.

Great that it works for you now. Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top