I am working on a winforms application, the application will attempt to capture an image and save it to the hard drive without the need to present the result or the live stream to the form.
I was using AForge and suddenly I started getting null in my image variable, I tried several other packages and they are all giving the same problem.
I want to know if there is a setting on my system or in my code that is preventing the image from being copied to the variable.
the last one I tried was Microsoft Media Capturing package and the code as follows.
System.Drawing.Imaging.ImageFormat format = null;
format = System.Drawing.Imaging.ImageFormat.Jpeg;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
string name = InitialSetup.currentLkr.Name /*+ #"\" + InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg"*/;
name = name.Replace(#"/", "_");
name = name.Replace(" ", "_");
name = name.Replace(":", "-");
name = #"D:\" + name;
StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync(name,CreationCollisionOption.OpenIfExists);
await photo.CopyAsync(sf, InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg", NameCollisionOption.ReplaceExisting);
await photo.DeleteAsync();
//img.Save(name);
//webcam.Stop();
return name+ InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg";
Related
I've been using this for a while and it's always worked fine. The project writes to a docx log file as it runs. I recently made a modification to the path it writes the log to for someone else to use. Since then, when I run it as a built exe it writes one line per page. But when I attempt to fix the problem, I can't recreate it running it in VS. From there it works like it always had.
Any ideas? A direction someone can point me toward?
public static void WritetoLogFile(string logUpdate)
{
DateTime now = DateTime.Now;
string logDate = now.ToString("MM-dd");
string folderNameDate = now.ToString("MM_dd_yyyy");
string folderName = folderNameDate + "_Logs";
string stateFolder = " ";
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + "//" + folderName);
string logName = logDate + "_" + Crawlspace.browser + "_" + Crawlspace.computerName + "_" + Crawlspace.SuiteTable + ".docx";
Crawlspace.LogFileName = logName;
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + folderName + "//" + stateFolder);
Crawlspace.LogFile = Crawlspace.networkSharePath + folderName + "//" + stateFolder + "//" + logName;
if (System.IO.File.Exists(Crawlspace.LogFile))
{
using (DocX document = DocX.Load(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
else
{
using (DocX document = DocX.Create(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
}
RESOLVED:
I checked the xceed.words.net.docx dll in the nuget manager and found there was an update. Updated to the latest and modified my using statements to reflect the update and it's now working....
using Image = Xceed.Document.NET.Image;
using Paragraph = Xceed.Document.NET.Paragraph;
using Picture = Xceed.Document.NET.Picture;
I am currently working on a project that sweeps a mailbox for attachments and when one is found it is placed in the user's directory. My problem is that when I check if the file exist in the path, I alter the attachment's name and add a counter and time stamp, that way it is not over written. However, when it goes into the condition and changes the file name it never updates the path variable to include the right value of the Clean name variable.
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
string path = employeeStarPath + "\\" + cleanName;
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
Now I am aware I can update the path var by calling path = employeeStarPath + "\\" + cleanName; again but I feel that this makes my code a bit confusing.
I might not understood your question but can you just call the line "string path = employeeStarPath + "\" + cleanName;" at the end instead before the if?
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
string path = employeeStarPath + "\\" + cleanName;
I have function in my app to edit the user details in that there is feature which allows us to edit the image in the picturebox.
What I am trying to achieve is if user choose to edit the image to another the app should delete the current image and use the new image and save to db. If users edit other details without touching picturebox then no changes should be made.
I have written below code but but it's not working can correct me or suggest better solution for what I am trying to achieve.
string picPath
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "Image files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
profilePicPictureBox.ImageLocation = FileName;
}
if (File.Exists(#"D:\Local Pictures\Users\" + fnameTextBox.Text + "_" + lnameTextBox.Text + "_" + userIdTextBox.Text + ".jpg"))
{
File.Delete(#"D:\Local Pictures\Users\" + fnameTextBox.Text + "_" + lnameTextBox.Text + "_" + userIdTextBox.Text + ".jpg");
picPath = (#"D:\Local Pictures\Users\" + fnameTextBox.Text + "_" + lnameTextBox.Text + "_" + userIdTextBox.Text + ".jpg");
profilePicPictureBox.Image.Save(picPath);
}
when i try to execute the above i am getting a exception on relative path
I have saved (Write) an image to "LocalFolder" not being picked up by the notification Toast.
StorageFolder systemLocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
string path = systemLocalFolder.Path + "\\" + R.GetResourceString("CachedImageFolder") +
"\\" + R.GetResourceString("CachedImagePrefix") + contact + ".png";
path = path.Replace(#"\", #"/");
path = #"file:///" + path;
image.SetAttribute("src", path);
binding.AppendChild(image);
After setting this image , the toast does not show up.
However doing this:
image.SetAttribute("#Assets/Logo.png", path);
Does show up the toast with the image.
But i want to write a file and then use it and not pick from App Package.
Win8+XAML+C#
The file:/// protocol isn't supported for Windows 8 Store apps BUT you don't need it anyway. Something like this should get you there:
path = #"ms-appdata:///local/" + R.GetResourceString("CachedImageFolder") + "/"
+ R.GetResourceString("CachedImagePrefix") + contact + ".png";
I am using an image control, but it does not display any image. When I see its viewsource, it displays the image path correct. The URL of the page is devweb.tsgdomain.com/americaneyenew/News.aspx
lblTitle.Text = dtNews.Rows[0]["NewsTitle"].ToString();
string strPhotosImage = dtNews.Rows[0]["Image"].ToString();
if (strPhotosImage != string.Empty)
{
string Extension = strPhotosImage.Substring(strPhotosImage.LastIndexOf("."));
// Server.MapPath("~/ENewsLetterFileUpload/NPH_" + strOriginalFileName + "_1.PDF");
ImgNews.ImageUrl = Server.MapPath("~/ENewsImage/" + iNewsID + "_1" + Extension);
//Server.MapPath("~/ENewsImage/" + iNewsID + "_1" + Extension);
//"../ENewsImage/" + iNewsID + "_1" + Extension;
ImgNews.Visible = true;
}
else
{
ImgNews.Visible = false;
}
Please help me as soon as possible.
you shouldn't use as server.mappath
ImgNews.ImageUrl = "~/ENewsImage/" + iNewsID + "_1" + Extension;
would be enough.
I think you have the wrong URL.
When you do :
String testURL = Server.MapPath("~/ENewsImage/" + iNewsID + "_1" + Extension);
Response.Redirect(testURL);
Is your image there?
Make sure the URL is correct by printing it to the screen or visiting it.