1

i want to ask how to upload my files outside the server (for security issue) i use teleric Rad UploadFiles (ASP.net web application)..the problem that i cannot specify the required path outside the server using the method

server.map("~\\..\\")

to go outside the server i get this

exception Cannot use a leading .. to exit above the top directory.

is there any way to determine a path outside the server

please help..

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

4 Answers4

3

Use a full path, like "c:\uploads" and be sure that the web process has permission to write to that folder

Ray
  • 21,485
  • 5
  • 48
  • 64
  • but when the application published on the server , can the server identify an absolute path like this??? – Anyname Donotcare Aug 12 '10 at 13:05
  • I do this with no problems on my servers. I suggest you store the path itself in the web.config file (appSettings section) so you can have different paths for dev and production servers. – Ray Aug 12 '10 at 13:22
  • thank u so much,i think this is the solution ,, please two questions(do u use Server.Map()function),,how to give the web process this permission – Anyname Donotcare Aug 12 '10 at 13:37
  • no need for Server.Map, since this path is outside your web site structure.Grant read, write, and modify rights on the folder to the user account under which your site runs (in IIS 6, right click on the site, select Directory Security, then look under Authentication and access control to see the anonymous user). – Ray Aug 12 '10 at 14:09
1

This is fully covered in the Telerik documentation for this control which can be found here. In brief:

[ASP.NET] RadUpload declaration

<telerik:RadUpload ID="RadUpload1" Runat="server" />
<asp:Button Runat="server" ID="Button1" Text="Submit"
  OnClick="Button1_Click" />

[C#] Click event handler

using Telerik.Web.UI;
...
protected void Button1_Click(object sender, System.EventArgs e)
{
  foreach (UploadedFile f in RadUpload1.UploadedFiles)
  {
      f.SaveAs( "c:\\uploaded files\\" + f.GetName(), true);
  }
} 
Lazarus
  • 41,906
  • 4
  • 43
  • 54
  • but when the application published on the server , can the server identify an absolute path like this??? – Anyname Donotcare Aug 12 '10 at 13:05
  • Of course, Server.MapPath just takes a path of the form "~/directory/directory/" and converts it to "C:\Inetapp\www\directory\directory". – Lazarus Aug 12 '10 at 13:09
  • thank you so much ,, but i don't know why my team leader tells me (don't use any absolute paths in your application as the server can't recognize them ,,he tells me to use Server.Map() instead but in this problem i wanna to upload outside the server and this method convert the path to be in the server) – Anyname Donotcare Aug 12 '10 at 13:17
0

I think you're running into a problem because of the server.map(..) call, can you not just use a hard coded path (read from config of course). So use something like "C:\UploadedFiles\" You'll need to make sure the user that ASP.NET is running under has the rights to write to that directory, etc.

Paul Hadfield
  • 6,088
  • 2
  • 35
  • 56
  • thank you so much please can you give me more details where in the config file and what is the alternative to Server.Map() and the repetitive question :: when the application published on the server , can the server identify an absolute path like this??? – Anyname Donotcare Aug 12 '10 at 13:08
0

I am using Internet Explorer 8, and had similar issues. I could upload from the server the upload page is hosted on, in IIS7. I could also upload from another different server but on the same domain as the webserver (that hosted the upload page). Both these worked.

But the upload from a PC that was not on the domain, did not upload, and gave the 500 error. I finally added the upload site on internet explorer to the Trusted Sites, and it worked fine. :)

Before that I checked rights on folders etc, and that was all ok. Also had size issues, then got a blog that said I should add:

<requestLimits maxAllowedContentLength="2000000000" /> <!-- bytes -->
</requestFiltering>

to the applicationHost.config file on the webserver in location C:\windows\system32\inetsrv\config\

In addition in IIS7 I also had to check the asp properties in server manager for the website that the upload page is on, changed the Limit Properties \ Maximum Requesting Entity Body Limit to match the size in the applicationHost.config file.

This is a classic asp website.

janisz
  • 6,292
  • 4
  • 37
  • 70