I have a question abou a change that I´m trying to do in the Photo Gallery Template.
WHat I want is to change the "upload a photo" to "insert a link" of a page. In other words, instead of having the photos saved in my server i want to just have the links.
The Idea is quite simple but I´m really stuck here. If anyone could help I would appreciate.
}
Page.Title =
"Upload
Photo to Gallery - "
+ gallery.Name;
if
(IsPost) {
var
numFiles = Request.Files.Count;
for
(int
i = 0;
i < numFiles; i++) {
var
file = Request.Files[i];
if
(file.ContentLength > 0)
{
var
fileUpload = new
WebImage(file.InputStream);
var
fileTitle = Path.GetFileNameWithoutExtension(file.FileName).Trim();
if
(fileTitle.IsEmpty()) {
fileTitle =
"Untitled";
}
var
fileExtension = Path.GetExtension(file.FileName).Trim();
mclazarini
Member
63 Points
57 Posts
Photo Gallery
Mar 26, 2012 05:12 PM|LINK
HI Everyone!
I have a question abou a change that I´m trying to do in the Photo Gallery Template.
WHat I want is to change the "upload a photo" to "insert a link" of a page. In other words, instead of having the photos saved in my server i want to just have the links.
The Idea is quite simple but I´m really stuck here. If anyone could help I would appreciate.
}
Page.Title =
"Upload Photo to Gallery - " + gallery.Name;
if (IsPost) {
var numFiles = Request.Files.Count;
for (int i = 0; i < numFiles; i++) {
var file = Request.Files[i];
if (file.ContentLength > 0) {
var fileUpload = new WebImage(file.InputStream);
var fileTitle = Path.GetFileNameWithoutExtension(file.FileName).Trim();
if (fileTitle.IsEmpty()) {
fileTitle =
"Untitled";
}
var fileExtension = Path.GetExtension(file.FileName).Trim();
var fileBytes = fileUpload.GetBytes();
db.Execute{
@"INSERT INTO Photos
(GalleryId, UserId, Description, FileTitle, FileExtension, ContentType, FileSize, UploadDate, FileContents) VALUES
(@0, @1, @2, @3, @4, @5, @6, @7, @8)", galleryId, WebSecurity.CurrentUserId, "", fileTitle, fileExtension,
fileUpload.ImageFormat, fileBytes.Length, DateTime.Now, fileBytes);
}
}
Response.Redirect(Href(
"~/Photo/View", db.GetLastInsertId()));
}
}
Thanks
SonicMan
Participant
1472 Points
228 Posts
Re: Photo Gallery
Mar 28, 2012 02:03 AM|LINK
Hi
When some one insert a photo by a link, you should save this link to DB.
That's easy,
http://msdn.microsoft.com/en-us/library/webmatrix.data.database.execute(v=vs.99).aspx