473,609 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Upload multiple images

Question

How to Upload multiple images in asp.net? (ex.Like a gmail file field)
Jul 23 '08 #1
1 2732


"Rajagopal" wrote:
Question

How to Upload multiple images in asp.net? (ex.Like a gmail file field)

Hi All,

<form id="form1" runat="server">
<input type="file" id="file_1" runat="server" /><input type="button"
onclick="addcon trol()"
value=" + " />
<div id="myDiv">
</div>
<br />
<asp:Button ID="btn_submit " runat="server" Text="Submit"
OnClick="btn_Cl ick" />
<br />
<input type="text" value="1" id="theValue" runat="server" />
<input type="text" id="FileID" runat="server" value="1" />
<input type="text" id="GetImageURL " runat="server" />
</form>

And Also Create Javascript Function.

// Addcontrol Function Used to Dynamically Create a File field Controls
function addcontrol()
{
var ni=document.get ElementById('my Div');
var numi=document.g etElementById(' theValue');
var num=(document.g etElementById(" theValue").valu e-1)+2;
numi.value=num;
var divname="my"+nu m+"div";

document.getEle mentById("FileI D").value=docum ent.getElementB yId("FileID").v alue+","+num;
var newdiv=document .createElement( 'div');
newdiv.setAttri bute("id",divna me);
newdiv.innerHTM L="<input type='file' id='file_"+num+ "'><input
type='button' onclick=\"addco ntrol()\" value=' + '><input type='button'
onclick=\"remov e('"+divname+ "','"+ num +"')\" value=' - '>";
ni.appendChild( newdiv);

}

// The Following function used to Remove a File field Control

function remove(divname, val)
{
var va=document.get ElementById("Fi leID").value.sp lit(",");
var dd="";
for(i =0;i<va.length; i++)
{
if(va[i]!=val)
{
dd+=va[i]+",";
}
}
if(dd.length>1)
{
dd=dd.substring (0,dd.length-1);
}
document.getEle mentById("FileI D").value=dd ;
var d=document.getE lementById('myD iv');
var olddiv=document .getElementById (divname);
d.removeChild(o lddiv)
}

The Following Function used to Get image URL
function GetImageUrlText ()
{
var getvalues="";
var hval=document.g etElementById(" FileID").value. split(",");
var len=hval.length ;

for(j=0;j<hval. length;j++)
{

getvalues+=docu ment.getElement ById("file_"+hv al[j]).value+",";
}
document.getEle mentById("GetIm ageURL").value= getvalues;
}

Then Go to Aspx.Cs page
You should call javascript function Page Load
btn_submit.Attr ibutes.Add("onc lick", "javascript:ret urn
GetImageUrlText ()");

The following code you put Button click(Upload Multiple Image)

protected void btn_Click(objec t sender, EventArgs e)
{
Array ImageUrl = GetImageURL.Val ue.Split(',');
for (Int32 i = 0; i < ImageUrl.Length ; i++)
{
if (ImageUrl.GetVa lue(i).ToString () != "")
{
string StrImage = ImageUrl.GetVal ue(i).ToString( );
string StrImageName =
StrImage.Substr ing(StrImage.La stIndexOf("\\") + 1);
file_1.PostedFi le.SaveAs(Serve r.MapPath("~/images/") +
StrImageName);
}
}
}

Please Try ...
Cheers,
Rajagopal.T
Jul 23 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10947
by: jmev7 | last post by:
Is there a script that will allow upload of multiple images at once to a FTP server, and simultaneously write that list to a MySQL table? I need to allow users to do something like this. Thanks.
4
2415
by: NohaKhalifa | last post by:
Dear All; I'm developing a web site and i need to make adminisration for this site it's a site for Real Estates . But I don't need the administration to be online .. I want them to fill data and images offline and then send them online... but i have a problem regarding the images i want it to be sent to the web site So i want if there is a possible way to fill data offline and
2
3830
by: Bonato Pierantonio | last post by:
Hi All, some one can help me? I need to upload an entire directory of images in a Web server using ASP.NET? How can I do it? Thanks
9
3824
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
2
4799
by: G | last post by:
Hello Friend, I am handling a module using ASP3.0 which has to upload an movie clipsof size 1 mb or 2 mb. i have a code which upload only files or images. So I need your help for this. If you know any code or any free component please share with me. Thanks G.
21
34378
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
12
2206
by: lawrence k | last post by:
I've a form that starts off like this: <form method="post" action="profile.php? id=5&formName=my_story_edit.htm" enctype="multipart/form-data"> <p>Email address:<br /> <input type="text" name="totalFormInputs" value="lawrence@krubner.com" /></p>
2
3249
by: sarayu | last post by:
Hi All, How can i select multiple images by using shift or control key from my hard disk and upload it by using a submit button.For this what we use for selecting different images and for uploading.Any interface is required?Is it possible only with PHP-MYsql and Javascript.Else what technology we use ? Thanks in advance
8
9846
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the page coding) does verify file size, if correct it places it on the server in the users folder and with the correct names and extension, creates the thumbnail and adds the correlating file name. However, it only adds the first file name to the database....
0
8095
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8588
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
8556
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8410
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
7030
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
4037
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
4103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2541
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
0
1407
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.