We have learn how to upload single image to Picasa Web Album. In this post we will learn how we can upload multiple image to Picasa web album. We will upload the images to our recently created Picasa web album "Google is the Best". We created this album in our post How to create new Picasa Web Album with Google Data API – Part 4?
I have designed following interface to upload multiple images to Picasa Web Album. We have a OpenFileDialog control on this form. Clicking on Browse button will launch the Open File Dialog box and we will select multiple image. The selected images will be added in the list view control. After clicking on Upload All Images button; the .NET code will upload all images to our Picasa web Album.
I am importing following Google Data API namespace in this program under each post.
using Google.GData.Client;
using Google.GData.Photos;
using Google.GData.Extensions;
using Google.GData.Extensions.Location;
using Google.Picasa;
The .NET code snippet on "Browse" button is following:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = true;
openFileDialog1.ShowDialog();
foreach(string myfile in openFileDialog1.FileNames)
{
listView1.Items.Add(new ListViewItem(myfile));
}
}
The .NET code snippet on "Upload All Images button is following:
private void button2_Click(object sender, EventArgs e)
{
//Create new Picasa Service
PicasaService myPicasa = new PicasaService("Vikash-Test-Picasa");
myPicasa.setUserCredentials("abc@gmail.com", "abcpassword");
//Create new URI by passing userid and AlbumID
Uri newURI = new Uri(PicasaQuery.CreatePicasaUri("abc", "5737335314773942337"));
//Upload all images to Picasa
foreach(ListViewItem photoFile in listView1.Items)
{
System.IO.FileInfo newFile = new System.IO.FileInfo(photoFile.Text);
System.IO.FileStream neFStream = newFile.OpenRead();
PicasaEntry newEntry = (PicasaEntry)myPicasa.Insert(newURI, neFStream, "Image/jpeg", "Test");
neFStream.Close();
}
System.Windows.Forms.MessageBox.Show("All Image has been uploaded");
}
After setting up the code; I run the form and click on Browse button. It open the Open File Dialog box. I have selected four images from my local machine folder.
I have added the selected images in the list view control. So we have total four images in the list that we are going to upload.
The next thing I did was to click on Upload All Images button. The code run successfully and uploaded all the images to our Picasa Web Album "Google is the Best".
I log into my Picasa web account and check the web album Google is the Best. The four images which I uploaded through .NET interface were right up there.
So our objective to upload multiple images have been achived.
Thanks! For reading till this point.