วันพุธที่ 16 พฤษภาคม พ.ศ. 2555

Create image gallery,store picture in SQL Server 2005 Express

How do the user add picture?
I have an example here like using Upload
C#
private void Btn_AddAtt_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
d.Filter = "Image (*.jpg, *.png)|*.jpg;*.png";
d.Multiselect = true;
if (d.ShowDialog() == true)
{
foreach (FileDialogFileInfo f in d.SelectedFiles)
{
Stream s = f.OpenRead();
byte[] fileBytes = new byte[s.Length];
int byteCount = s.Read(fileBytes, 0, (int)s.Length);
string fileContent = Convert.ToBase64String(fileBytes);
s.Close();
//Upload here
// mydata.UploadFileAsync(f.Name, fileContent);
}
}
}
mydata.LoadImage_Completed(....)
{
byte[] m;
Stream b;
if (e.Error == null)
{
List<ImageFile> k = e.Result as List<ImageFile>;
//using for-looping with int i to get the content and change it back to Image
m = Convert.FromBase64String(k[ i].Content);
b.WriteByte(m);
BitmapImage k = new BitmapImage();
k.SetSource(b);
Image mypic = new Image();
mypic.Source = k;
LayoutRoot.Children.Add(mypic);
}
}
In the WCF
public void UploadFile(string fileName, string text)
{
//you have now the text with Base64 Configuration, you can insert it into your SQL database
// next time you can get it back by loadImage
}
public class ImageFile
{
public string Name { get; set; }
public string Content { get; set; }
}
public string LoadImage()
{
//you can now find all the Row in the Database and send back the Name and Text
//you may return List<ImageFile>
}
I didnt try them all in VS but the upload part should work very well

ไม่มีความคิดเห็น:

แสดงความคิดเห็น