ASP.NET C# image file not get in folder - asp.net

string filename = bupload.PostedFile.FileName; //upload pdf file
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(filename);
System.Drawing.Image img = System.Drawing.Image.FromFile("watermark.jpg");// upload image
pdf.Pages[0].BackgroundImage = img;
pdf.SaveToFile("watermark.pdf");
how can add watermark and save a file in particular folder in my website and no change he name of file file name is same as uploaded file name

Related

how to send an image via email without saving it to a folder before

I am uploading images to an asp.net website using fileupload and i need to send the uploaded images via email to do this i am saving the image to a folder on the erver and then i am sending the image but can i send it without saving it to a folder before or if i need to save it to a folder can i delete it as soon as it's sent?
thanks.
my code:
string filename = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("UploadImages/" + filename));
string attachmentPath = Server.MapPath("UploadImages/" + filename);
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentType.Name = Path.GetFileName(attachmentPath);
mail.Attachments.Add(inline);
using System.Net.Mail;
[WebMethod]
public void SendFile(HttpPostedFileBase file)
{
//...setup mail message etc
Attachment attachment = new Attachment(file.InputStream, file.FileName);
message.Attachments.Add(attachment);
}

How to load image using URL from the WEF-INF\image folder to write in a PDF document

How to get image URL and used to write in a PDF document.
ClassPathResource classPathResource = new ClassPathResource("Image.png");
i have added the image logo like this in my pdf file
String imgPath = "/img/Kavi025.jpg";
String absoluteImgPath = getServletContext().getRealPath(imgPath);
System.out.println(absoluteImgPath);
Document document= new Document();
PdfWriter writer= PdfWriter.getInstance(document, new FileOutputStream("d:\\Kavi.pdf"));
document.open();
Image img = Image.getInstance(absoluteImgPath);
img.setAbsolutePosition(100, 200); // x-axis and y-axis position
writer.getDirectContent().addImage(img);
document.close();
System.out.println("end of method");

I am not able to save image into Folder

I am trying to save a image in specified folder but it doesn't saving image but code is working for excel file storing...did i missed something here....please suggestions needed.
string filename = Path.GetFileName(imgUploadControl.PostedFile.FileName);
string folder = Server.MapPath("~/Files/");
imgUploadControl.PostedFile.SaveAs(Path.Combine(folder, filename));
string filePath = Path.Combine(folder, filename);
imglogo.ImageUrl = Server.MapPath("~/Files/" + imgUploadControl.FileName);

Image Not Displaying when the path is Temp Folder in Asp.net

I am getting the content of Image in byteArray format from the database and displaying it in the Content image tag in ASP.NET.The problem is that when I save the image file in a specific location in my working folder and display the image,it is working fine.But if I try to save the image in a temporary folder and pass the temporary folder URL to image tag it doesn't display the image.
code:
Bitmap bi = new Bitmap(byteArrayToImage(FileUpload1.FileBytes));
//This code working fine
string path = Server.MapPath("Images/") + FileUpload1.PostedFile.FileName;
bi.Save(path , ImageFormat.Jpeg);
Image1.ImageUrl = "Images/" + FileUpload1.PostedFile.FileName;
//This code didn't displaying the image.
bi.Save(Path.GetTempPath() + FileUpload1.PostedFile.FileName, ImageFormat.Jpeg);
Image1.ImageUrl = Path.GetTempPath() + FileUpload1.PostedFile.FileName;
what is the problem with the tempFolder here?.I am using the Windows7 OS.Here i am using the temparory folder for automatically deleting the created images from the folder.
Thank you
Did you debug and check if the ImageUrl is correct

why is the image icon blank/white when fileupload.saveas

i use vb.net
i trying to do a file upload, i want to image to save to image folder, however, the image don't know appear in the directory that i indicate
if i click on "show all file", the image appear, but the image icon is blank or white like the image below show
so i click on that image and click on "include it in the project" , however, it shouldnt be the case that i everytime upload an image, i need to redo that again
so how should i allow don't appear the white icon and to always appear in the upload folder when i upload a image instead of manually click on the image to include in ?
this is my code
Protected Sub uploadImage()
Dim filename As String = FileUploadImg.FileName
Dim fileType As String = filename.Substring(filename.Length - 4).ToLower()
If (fileType = ".gif") Or (fileType = ".jpg") Or (fileType = ".png") Then
FileUploadImg.SaveAs("C:\Users\Jane\Desktop\project\FileUpload\FileUpload\WebRole1\images\" & txtboxName.Text & "_" & FileUploadImg.FileName)
Else
MsgBox("failed")
End If
End Sub
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
uploadImage()
'End If
End Sub
this is the image of how it look like
You have to save posted file to persisted storage on the web server and map files to some URL so they can be accessed from the internet.
In Azure environment local disk (like c:) is not persisted (imagine multiple web-roles - how could you serve same image from other instances).
Solution is Azure Blob Storage (you have to set-up it in you Azure Management Console) and upload posted file to the Blob Storage Container.
// Setup the connection to Windows Azure Storage
var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
var blobClient = storageAccount.CreateCloudBlobClient();
// Get and create the container
var blobContainer = blobClient.GetContainerReference("public-images");
blobContainer.CreateIfNotExist();
// Allow blob to be downloaded
containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
blobContainer.SetPermissions(containerPermissions);
// Get the target blob reference
var blobAddressUri = String.Format("{0}{1}", fileName); //create random fileName here
var blob = BlobContainer.GetBlobReference(blobAddressUri);
// Set blob Content-Type
blob.Properties.ContentType = FileUploadImg.PostedFile.ContentType ;
// Upload to the blob storage account
blob.UploadFromStream(FileUploadImg.FileContent);
Your file is now available at blob.Uri.
You have to designate a directory where your uploads will be placed. For example, if I create a new project in C:\, Website1, the direcotry would be C:\Website1. I'd then create a directory under to store uploads: C:\Website1\uploads and make sure to set permissions to read/write for IIS account. I'd then do:
string uploadPath = MapPath( "pictures\\" );
this.fileUpload1.SaveAs( uploadPath + this.fileUpload1.FileName );
Once the file is in the upload directory, I can move it anywhere I like.

Resources