473,587 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page fails if there is no Image uploaded

17 New Member
Hi,

I have a webform that uload images as well. The image is uploaded well but the problem arises when the user does not upload any image. I want the form to save nothing for the image_name in the database if there is no image loaded but it does not get to the art of saving to the database, please see my code below and the error I am getting:

Expand|Select|Wrap|Line Numbers
  1. if( filMyFile.PostedFile != null )
  2.  {
  3.  
  4.      string strFilename;  
  5.      strFilename = filMyFile.PostedFile.FileName;    
  6.      strFilename = System.IO.Path.GetFileName(strFilename);
  7.      filMyFile.PostedFile.SaveAs(@"C:\Advert_images\"+strFilename);
  8.  }
  9. else
  10. {
  11.  
  12. // No file
  13.  
  14. }
This is the error I am getting when there is no image uploaded:
Exception Details: System.IO.Direc toryNotFoundExc eption: Could not find a part of the path "C:\Advert_imag es\".



Any help will be highly appreaciated.
May 7 '09 #1
8 1620
Bassem
344 Contributor
The exception make me think that your system have no folder with the name Advert_images in partition C.
But what line arise this exception.
May 11 '09 #2
zizi2
17 New Member
Hi Bassem, thanks. It fails on the line 'filMyFile.Post edFile.SaveAs(@ "C:\Advert_imag es\"+strFilenam e', I would have thought it does not have to go inside the if statement if filMyFile.Poste dFile is null, it would simply go to the ELSE part and do nothing?
May 12 '09 #3
Bassem
344 Contributor
Sorry for late, my keyboard is damaged and I had to buy a new one.
filMyFile.Poste dFile will not equal null at any way. So check like this:
Expand|Select|Wrap|Line Numbers
  1.         if (filMyFile.PostedFile.ContentLength != 0)
  2.         {
  3.             string strFilename;
  4.             strFilename = filMyFile.PostedFile.FileName;
  5.             strFilename = System.IO.Path.GetFileName(strFilename);
  6.             filMyFile.PostedFile.SaveAs(@"C:\Advert_images\" + strFilename);
  7.         }
  8.         else
  9.         {
  10.  
  11.             // No file
  12.  
  13.         }
Now the exception arise because the folder Advert_images doesn't exist. Be sure you already created it.

Regards,
Bassem
May 13 '09 #4
zizi2
17 New Member
Thanks, it works like a charm when I use if (filMyFile.Post edFile.ContentL ength != 0) . Sorry but I'm new to .Net programming so I need help again. I am trying to display a computer name in a texbox but I am failing, please look at my code below:

string macname = Environment.Mac hineName;
txtECN.Text = macname[0].ToString();
May 13 '09 #5
zizi2
17 New Member
How do I concatenate two textbox values into one table column, can anyone please help?
May 14 '09 #6
Curtis Rutland
3,256 Recognized Expert Specialist
What kind of table are you talking about?

String concatenation is simple enough:
Expand|Select|Wrap|Line Numbers
  1. string s = textbox1.Text + textbox2.Text;
Also, please don't keep posting new questions in your old thread. One topic, one thread. New topic, start a new thread.

MODERATOR
May 14 '09 #7
Bassem
344 Contributor
@zizi2
Environment.Mac hineName returns a string, but in the next line you get only the first character only macname[0].

It should be like that :
Expand|Select|Wrap|Line Numbers
  1. string macname =   Environment.MachineName;
  2. txtECN.Text = macname;
  3.  
May 14 '09 #8
zizi2
17 New Member
Thanks for all your help
May 15 '09 #9

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

Similar topics

2
2861
by: Gary \(Girish\) | last post by:
Hello: I am using SA-FileUp to enable members to upload their product images to my ISP sever. When member uploaded a new image file, the file name is replaced with the member ID and the old file is then overwrited. Here is the problem: Member can uploaded new image at "Upload page" BEFORE viewing the new image at the "Detail page" without any problem. However, when member 1st viewed the image at the "Detail page" and then upload the...
11
3239
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will just display it below: The following code contains the script to process the uploaded file, the form to upload the file and then a few links to view the file from
2
1870
by: Paul Gorman | last post by:
I am using the control type = file to perform a file upload. When I click on the browse button to go select the image I want to upload it places in the text box a local path (C:\images\image.jpg for example). This is where the image resides that I want to upload. Then I proceed to click on upload so that I can run through my code to do the upload process: string strConnection = "some connection string"; SqlConnection oCon = new...
2
13454
by: engwar1 | last post by:
I have a page that my users will go to to upload files to my website. As I want to reuse the file upload code on multiple pages I put the file upload textbox/buttons on a user control which I plan to include in multiple aspx pages where they'll be able to upload images for other purposes. On the first page that I'm working on where users will be doing the upload (which I'll call the 'parent' page) I also have a DataGrid where I display...
6
1783
by: Neo Geshel | last post by:
About 4 months ago I came across this one web page that talked about streaming raw image data (from a database, for example) directly to a web page without requiring a secondary ASPX page to output the data as an image. I cannot remember if it talked about having the raw data inline with the HTML page, or having it bound to a server control. Does anyone know the article that I am talking about? TIA
6
1803
by: Dave Keen | last post by:
Hi all I am writing a webpage which asks the user for the name of a picture file, then reads the file, resizes if necessary and saves it to the server. The code to read the file is... ' Set permissions for loaded file. Dim FileIOPerm1 As System.Security.Permissions.FileIOPermission FileIOPerm1 = New
1
1477
by: simon2x1 | last post by:
i uploaded 5image which is displayed in the respective rows and columns.the first image is in the 1row,1coluumn the 3 image is in the 1row 3clomn the 5image is in the 2row 2column.i want to echo next when the 6image is uploaded and when i click next the same page should show displaying the 7image which is just uploaded and is in the 1row and 1column <?php $db_database = "files"; $dbconnect =...
3
4410
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
2
5062
by: luke noob | last post by:
its quite hard to explain sorry in advance..... I have an upload page that sends infomation to a table in the database, id, title, src, tn_src, discription etc. all this information is then displayed on a page called image.php. Once clicked on a small image in my index page it goes to image.php page showing the bigger image with all the information i uploaded around it. image.php has its own id so it can display different infomation...
0
7927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8220
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8222
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6632
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2367
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.