473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to correct this file upload error?

Access to path is denied

This code is working properly in my system but in web server it is showing this error

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         string id = Request.QueryString["id"];
  4.         i++;
  5.         if (upimage.HasFile)
  6.         {
  7.             if (CheckFileType(upimage.FileName))
  8.             {
  9.  
  10.                 string ext = Path.GetExtension(upimage.FileName);
  11.                 string filename = Path.GetFileName(upimage.FileName);
  12.                 string name = Server.MapPath("~/upload/") + s + i + ext;
  13.                 upimage.SaveAs(name);
  14.                 SqlDataSource1.InsertParameters["id"].DefaultValue = id;
  15.                 SqlDataSource1.InsertParameters["path"].DefaultValue = name;
  16.                 SqlDataSource1.Insert();
  17.             }
  18.  
  19.         }
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.     bool CheckFileType(string filename)
  26.     {
  27.         string ext = Path.GetExtension(filename);
  28.         switch (ext.ToLower())
  29.         {
  30.             case ".gif":
  31.                 return true;
  32.             case ".png":
  33.                 return true;
  34.             case ".jpg":
  35.                 return true;
  36.             case ".jpeg":
  37.                 return true;
  38.             default:
  39.                 return false;
  40.         }
  41.     }
  42.  
  43.     void Page_PreRender()
  44.     {
  45.         string upfolder = MapPath("~/upload");
  46.         DirectoryInfo dir = new DirectoryInfo(upfolder);
  47.         DataList1.DataSource = dir.GetFiles();
  48.         DataList1.DataBind();
  49.     }
  50.  
  51.     protected void Delete_File(object sender, DataListCommandEventArgs Args)
  52.     {
  53.  
  54.         File.Delete(Server.MapPath("~/upload")+ Args.CommandName);
  55.         Page_PreRender();
  56.  
  57.     }
  58.  
  59.     protected void Page_Load(object sender, EventArgs e)
  60.     {
  61.         Class1.i = 0;
  62.     }
  63.         public Int32 return_number_class()
  64. {
  65. Class1 s = new Class1();
  66. return s.return_number();
  67. }
  68.     public class Class1
  69. {
  70.         public Class1()
  71.         {
  72.  
  73.         }    
  74.     public  static Int32 i =0 ;
  75.     public Int32 return_number()
  76.     {
  77.         i++;
  78.         return i;   
  79.     }
  80.  
  81. }
  82.  
Mar 22 '11 #1
1 4904
kadghar
1,295 Expert 1GB
The code is right. Your privileges in the remote server are not. Perhaps you should check the folder you're attempting to write in is web writable.
Mar 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: dave | last post by:
Hello, I'm trying to get the below script working, adapted from the manual on php.net. Although i am getting success file uploading, i do not see the file in the tempoary area. And i'm not sure...
2
by: AMC | last post by:
Hi, I'm using a free component to upload image files to the web server. I'm getting this error when I try to upload SaveBinaryData error '800a0bbc' ...
5
by: Arthur Jacobs | last post by:
Good day, I am trying to upload a file to the server. http://chops.novatrope.com/game/test/form2.html Here is some more debugging info:Array ( =Array ( =Pequot.gif =>
0
Atli
by: Atli | last post by:
Hi. I'm trying to use php code I wrote last year when I was using Apache, so I'm pretty sure the code works. Its a simple code to upload an image and create a thumb of the image in another...
3
chunk1978
by: chunk1978 | last post by:
hi there... i have the following codes (HTML and PHP) on my Apache Localhost: HTML: titled "Form.html" <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input...
5
chunk1978
by: chunk1978 | last post by:
hi there... i have the following codes (HTML and PHP) on my Apache Localhost: HTML: titled "Form.html" <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input...
0
by: not a freek | last post by:
I am trying to upload file of about 17 MB, but it always returns me with error "Maximum request length exceeded. " I have changed my webconfig file & added value <httpRuntime ...
0
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
I have a page with four <input type=filecontrols on it. When i upload less than four meg across all four inputs, the files upload correctly. When i upload more than four meg, i get an error message...
12
by: GuangXiN | last post by:
I want the file upload element disappear, instead of it, I place a text box and a button with my own css defination. but it doesn't work on IE7. What should I do now? <form action="upload.php"...
4
rahulephp
by: rahulephp | last post by:
i think i am missing something in the below script: It shows error an do not upload files to destination: Let me know how to solve this: <?php if (isset($_POST)) { $uploadArray=...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.