Resource file modification date - c#

I am getting an image from a resource file like this:
Image img = (Image)Resources.ResourceManager.GetObject(imgName) as Image;
Is there a way to get the modification date of this image?

Sorry, you won't be able to access that information as the image is loaded into the assembly as binary information, not as a file.

Related

Umbraco GetCropUrl not giving me a valid URL with Image Cropper

I'm using the image cropper on my media type > Image > Upload Image. This seems to be the best solution for creating responsive images in the media library.
However, this presents me with the problem of finding out how to get the URL for my images now.
Usually for Image Croppers I would use this code:
#Model.Content.GetCropUrl("image", "my-crop-name")
However if I try to get the image crop this way I get this instead:
<img src="Umbraco.Web.Models.DynamicPublishedContent?mode=pad&rnd=131108182860000000" />
I was expecting to get an image URL with the crop I specified. This works fine for standard image croppers but not ones on my images in the media library. Why is that? And how should I get the crop URL for these images?
I'm using v7.4.2
In order to get a crop URL for an image in the media section you first need to retrieve the image as IPublishedContent. You can do this as follows:
var imageId = Model.Content.GetPropertyValue<int>("image");
var image = Umbraco.TypedMedia(imageId);
Or if you're using the excellent Core Property Value Converters package you can retrieve it directly without having to perform the conversion:
var image = Model.Content.GetPropertyValue<IPublishedContent>("image");
You then need to call the GetCropUrl() method on your image. If you've replaced the default Upload property with an Image Cropper property, and kept the property alias the same (umbracoFile), you can just pass in the crop alias:
var cropUrl = image.GetCropUrl("my-crop-name");
If the alias of your Image Cropper property is different to the default you will need to pass that as an additional argument:
var cropUrl = image.GetCropUrl("imageCropperAlias", "my-crop-name");
For images directly from the media libary without an Image Cropper data type. I use somethings like this:
<img src="#photo.Url?mode=crop&width=634&height=634" alt="#photo.Name" />
Not very pretty but it works perfectly.

Where i can store image for custom control?

Now, i developing a WinForms application. I need to create a custom control. My custom control uses a pictures. I don't want store these pictures in project resources file.
global::Wrigley_Data_Mart_Manager_2.Properties.Resources.previous_16x16;
I want to store pictures in resources file of custom control. But it's very uncomfortable. (designer always delete pictures from there). Where i can store image for my custom control? I want to my custom control was self-sufficient and that it can be used in other projects.
If you don't want to use a Resource (resx) then you could always include the image file within the project as an embedded resource.
You would create a folder to hold the image(s), and invoke "Add Existing", adding the images you'd like to embed into the project. Then in the Properties window for each file, for the "Build Action" selection, highlight the "Embedded Resource" option.
To access that file, you'd call Assembly.GetManifestResourceStream(string) with the full namespace of the project + the folder path within the project:
For Example, with Project Name: "MyCompany.MyTestProject" and you store the image(s) in the "Images" folder as "Images/image1.gif",
The namespace would then be:
Assembly.GetManifestResourceStream("MyCompany.MyTestProject.Images.image1.gif")
An alternative could be converting them to byte arrays and storing them as BLOBs in your database.
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
Then convert them back:
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}

Extracting a image from a WebBrowser Control

My aim is to extract an image from a loaded webbrowser control.
// get the image link from the image element ID.
string imageLink = wbVideos.Document.GetElementById("sbvdcapimg").GetAttribute("src").ToString();
//Download the image into a bitmap
Bitmap image = new Bitmap(new System.IO.MemoryStream(new System.Net.WebClient().DownloadData(imageLink)));
so the code works for most pictures, but i receive me a format error when i use it with the link below.
The error is thrown when i parse this link into my code: "http://www.swagbucks.com/?cmd=cp-get-captcha-image&ctype=1&tai=478817685&sid=0.4015013770493371"
(Please Note to view the image you need to login!)
Notice how the image does not end in a extension, this is most likely causing the error.
Example of the extracted link:
so, my question, how can i make my code accept this link as a valid image file?

i want to save a image with out user interaction in C#

I m scanning image in a form i want to save the image with out user interaction in C# can any one help..
string chktemp = #"C:\"+pic+".tif";
Bitmap bm= new Bitmap(from file);//Here it is asking already saved file with out this i want to save just now scanned image from form
bm.Save(chktemp);
Use IO to check if the current file exists, and if so delete it first.
See: System.IO documentation
File.Exists
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
File.Delete
http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
Load the Image File to Stream ,than you can Create Bitmap from Stream ,which will close the File Read Operation in source Image .

save image from fileupload

I am using fileupload control to have image on the form and that that image has to be saved on some folder in hard disk say "E:\\asp_net".
Is there any possible way to save image on disk from fileupload and if there is any other image with same name, it should be overwritten?
Why do you need to save the file in your machine's E drive?
Your ultimate option should be in your Application Folder. It should be like...
FileUpload1.SaveAs(Server.MapPath("~/AppFolderName/" + FileName));
You're looking for the cunningly-named SaveAs method.
following videos cover for your needs;
http://www.asp.net/general/videos/how-do-i-simple-file-uploads-in-aspnet
http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-1
http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-2
var filename = Path.Combine(#"E:\asp_net", myFileUploadControl.FileName);
if (File.Exists(filename))
File.Delete(filename);
myFileUploadControl.SaveAs(filename);

Categories