Showing posts with label uploadfile. Show all posts
Showing posts with label uploadfile. Show all posts

Wednesday, March 28, 2012

system.IO.File.Exists doesnt working for file that is outside my virtual directory

hi

i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no

if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.

so how to select file from any folder on my PC and chech that it exist
or notIt may have to do with the ASP.net user in IIS not having read
permissions on the directories?

Max wrote:

Quote:

Originally Posted by

hi
>
i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no
>
if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.
>
so how to select file from any folder on my PC and chech that it exist
or not


Are you using an absolute path or a relative path to the file?

"Max" wrote:

Quote:

Originally Posted by

hi
>
i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no
>
if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.
>
so how to select file from any folder on my PC and chech that it exist
or not
>
>


followin is the error i am getting

Server Error in '/' Application.
------------------------

Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg"
is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
What do you not understand about the exception's explanation?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?

"Max" <mahesh.anjani@.gmail.comwrote in message
news:1155306880.304856.71550@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

followin is the error i am getting
>
Server Error in '/' Application.
------------------------
>
Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
>
Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg"
is denied.
>
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.
>
To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.
>
Source Error:
>
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
>
>
Stack Trace:
>
>
[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
>

Saturday, March 24, 2012

System.Net.WebClient and UploadFile() Problem

I am using WebClient to upload a file to a remote server. The call I'm
making looks as follows:
webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/Fed
eration.Zip",
@dotnet.itags.org."C:\Temp\Federation.Zip");
'Federation' is a virtual directory on the server I'm attempting to upload
the file to. The URL is valid and the file I'm attempting to transfer
exists. I keep getting 404 errors (not found). It's not clear to me exactly
what cannot be found. If I attempt to download this exact file from the same
exact URL using webClient.DownloadFile, it works fine!
Thanks for the help - Amos.You can not simply upload file on a server.
Something should wait for that file at the server end.
So url http://sdtpcal.someserver.com/Feder.../Federation.Zip to
download file looks correct.
but to upload you must write an ASPX page that will accept file and save to
the folder on a server.
George.
"Amos Soma" <amos_j_soma@.yahoo.com> wrote in message
news:OqGt9oK7GHA.1248@.TK2MSFTNGP03.phx.gbl...
>I am using WebClient to upload a file to a remote server. The call I'm
>making looks as follows:
> webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/F
ederation.Zip",
> @."C:\Temp\Federation.Zip");
> 'Federation' is a virtual directory on the server I'm attempting to upload
> the file to. The URL is valid and the file I'm attempting to transfer
> exists. I keep getting 404 errors (not found). It's not clear to me
> exactly what cannot be found. If I attempt to download this exact file
> from the same exact URL using webClient.DownloadFile, it works fine!
> Thanks for the help - Amos.
>
Thus wrote George Ter-Saakov,

> You can not simply upload file on a server.
> Something should wait for that file at the server end.
> So url
> http://sdtpcal.someserver.com/Feder.../Federation.Zip to
> download file looks correct.
> but to upload you must write an ASPX page that will accept file and
> save to the folder on a server.
You only need a web application endpoint for POST requests. If the OP can
use PUT, the web server may support this without any special user code (IIS
does for sure).
Both WebClient.UploadFile(uri, "PUT", fileName) and WebClient.OpenWrite(uri,
"PUT") will do the trick.
Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

System.Net.WebClient and UploadFile() Problem

I am using WebClient to upload a file to a remote server. The call I'm
making looks as follows:

webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/Federation.Zip",
@dotnet.itags.org."C:\Temp\Federation.Zip");

'Federation' is a virtual directory on the server I'm attempting to upload
the file to. The URL is valid and the file I'm attempting to transfer
exists. I keep getting 404 errors (not found). It's not clear to me exactly
what cannot be found. If I attempt to download this exact file from the same
exact URL using webClient.DownloadFile, it works fine!

Thanks for the help - Amos.You can not simply upload file on a server.
Something should wait for that file at the server end.

So url http://sdtpcal.someserver.com/Feder.../Federation.Zip to
download file looks correct.

but to upload you must write an ASPX page that will accept file and save to
the folder on a server.

George.

"Amos Soma" <amos_j_soma@.yahoo.comwrote in message
news:OqGt9oK7GHA.1248@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I am using WebClient to upload a file to a remote server. The call I'm
>making looks as follows:
>
webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/Federation.Zip",
@."C:\Temp\Federation.Zip");
>
'Federation' is a virtual directory on the server I'm attempting to upload
the file to. The URL is valid and the file I'm attempting to transfer
exists. I keep getting 404 errors (not found). It's not clear to me
exactly what cannot be found. If I attempt to download this exact file
from the same exact URL using webClient.DownloadFile, it works fine!
>
Thanks for the help - Amos.
>
>


Thus wrote George Ter-Saakov,

Quote:

Originally Posted by

You can not simply upload file on a server.
Something should wait for that file at the server end.
So url
http://sdtpcal.someserver.com/Feder.../Federation.Zip to
download file looks correct.
>
but to upload you must write an ASPX page that will accept file and
save to the folder on a server.


You only need a web application endpoint for POST requests. If the OP can
use PUT, the web server may support this without any special user code (IIS
does for sure).

Both WebClient.UploadFile(uri, "PUT", fileName) and WebClient.OpenWrite(uri,
"PUT") will do the trick.

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

System.Net.WebException:

Hi,
I am trying to make a simple file updload WinForm app.
Here's the code:
WebClient webClient = new WebClient();
webClient.UploadFile(new Uri("http://localhost/WebSite/Upload.aspx"),
"c:\\bin.zip");

My IIS 5.1 Web server uses default configuration.
If the file is less than 5Mo everything works fine. If the file is too big I
get this exception:
System.Net.WebException: The underlying connection was closed: An unexpected
error occurred on a receive. --> System.IO.IOException: Unable to read data
from the transport connection: An existing connection was forcibly closed by
the remote host. --> System.Net.Sockets.SocketException: An existing
connection was forcibly closed by the remote host

I will never have to upload more than 30Mo.
Do you now how I can correct this issue ?In the web.config file, the httpRunTime element has a maxRequestLength which
restricts the length in bytes of any HTTP request. The default is 4MB.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"zolof" <zolof@.discussions.microsoft.com> wrote in message
news:C12D293F-C3B4-401C-99A6-7A10DB48B8BE@.microsoft.com...
> Hi,
> I am trying to make a simple file updload WinForm app.
> Here's the code:
> WebClient webClient = new WebClient();
> webClient.UploadFile(new Uri("http://localhost/WebSite/Upload.aspx"),
> "c:\\bin.zip");
> My IIS 5.1 Web server uses default configuration.
> If the file is less than 5Mo everything works fine. If the file is too big
> I
> get this exception:
> System.Net.WebException: The underlying connection was closed: An
> unexpected
> error occurred on a receive. --> System.IO.IOException: Unable to read
> data
> from the transport connection: An existing connection was forcibly closed
> by
> the remote host. --> System.Net.Sockets.SocketException: An existing
> connection was forcibly closed by the remote host
> I will never have to upload more than 30Mo.
> Do you now how I can correct this issue ?
That's great. Thanks a lot for your help.

System.Net.WebException:

Hi,
I am trying to make a simple file updload WinForm app.
Here's the code:
WebClient webClient = new WebClient();
webClient.UploadFile(new Uri("http://localhost/WebSite/Upload.aspx"),
"c:\\bin.zip");
My IIS 5.1 Web server uses default configuration.
If the file is less than 5Mo everything works fine. If the file is too big I
get this exception:
System.Net.WebException: The underlying connection was closed: An unexpected
error occurred on a receive. --> System.IO.IOException: Unable to read data
from the transport connection: An existing connection was forcibly closed by
the remote host. --> System.Net.Sockets.SocketException: An existing
connection was forcibly closed by the remote host
I will never have to upload more than 30Mo.
Do you now how I can correct this issue ?In the web.config file, the httpRunTime element has a maxRequestLength which
restricts the length in bytes of any HTTP request. The default is 4MB.
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"zolof" <zolof@.discussions.microsoft.com> wrote in message
news:C12D293F-C3B4-401C-99A6-7A10DB48B8BE@.microsoft.com...
> Hi,
> I am trying to make a simple file updload WinForm app.
> Here's the code:
> WebClient webClient = new WebClient();
> webClient.UploadFile(new Uri("http://localhost/WebSite/Upload.aspx"),
> "c:\\bin.zip");
> My IIS 5.1 Web server uses default configuration.
> If the file is less than 5Mo everything works fine. If the file is too big
> I
> get this exception:
> System.Net.WebException: The underlying connection was closed: An
> unexpected
> error occurred on a receive. --> System.IO.IOException: Unable to read
> data
> from the transport connection: An existing connection was forcibly closed
> by
> the remote host. --> System.Net.Sockets.SocketException: An existing
> connection was forcibly closed by the remote host
> I will never have to upload more than 30Mo.
> Do you now how I can correct this issue ?
>
That's great. Thanks a lot for your help.