I have spent quite a while trying to solve this problem, but to no avail. I have searched stackoverflow as well as Google and have not been able to resolve my (seemingly) simple problem.
I am getting a FileNotFoundException in the following line:
Image.FromFile("\\Resources\\Icons\\key-icon.png");
The folders and image are really there, and I can't see what the problem is.
You should consider that it is started from "yourproject/bin/Release" so you need to go up 2 directories. Do this:
Image.FromFile("..\\..\\Resources\\Icons\\key-icon.png");
Try using an absolute path not a relative one... i.e.
Image.FromFile(Server.MapPath(#"~\Resources\Icons\key-icon.png"));
Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
#"Resources\\Icons\\key-icon.png"))
Base-directory Combine your file-name
You may be missing a leading ".":
Image.FromFile(".\\Resources\\Icons\\key-icon.png");
Internally, Image.FromFile uses File.Exists to check whether the file exists. This method returns false when:
the file does not exist (makes sense)
the current process identity does not have permission to read the file
It may be that the second option is your problem.
And another possibility: is Resources a network share? In that case you should use the following:
Image.FromFile("\\\\Resources\\Icons\\key-icon.png");
For this case I discovered that sikuli does not automatically detect the root folder of the project. What you should do for this case is specify the folder using the command System.getProperty("user.dir");
import org.sikuli.script.*;
public class Test {
public static void main(String[] args) {
Screen s = new Screen();
try{
String pathYourSystem = System.getProperty("user.dir") + "\\";
s.click(pathYourSystem + "imgs/spotlight.png");
//s.wait(pathYourSystem + "imgs/spotlight-input.png");
//s.click();
s.write("hello world#ENTER.");
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
Related
I think this is a rather straightforward issue, but I don't have much information to go on. I have this code to try and read a DWG file into memory, so that I can read and manipulate the data. I am getting an error that the parameter "Value" cannot be null.
While that does let me know something is wrong, how do I proceed in figuring out what exactly this value is so that I can fix it?
string basePath = Path.Combine($"{Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)}", "temp");
string fileName = Path.Combine(basePath, "ATemplateV0.2.dwg");
if(File.Exists(fileName))
{
DwgReader dwgReader = new(fileName);
try
{
DxfModel dxfModel = dwgReader.Read();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
WW CadLib needs a license to run, if you don't have one that may be causing the error.
The code example in the answer from #b166er is referring to an Open Source library called ACadSharp to read dwg/dxf files from one of my repositories.
Right now you can use a pre-release version of it in Nuget
You can pass a onNotification event into the DwgReader constructor that might give you more information. Examples here: https://github.com/DomCR/ACadSharp/blob/master/ACadSharp.Examples/Program.cs
I'm not entirely sure at all why this is happening...
So I have a ExternalCommand and an application for making a ribbon tab and button. These two programs are in the same solution and under the same namespace, which allows me to have fewer files to deal with. When I create a button for my command, I want to put in the current path of the application that is currently running. I do this with Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll (where AddInsAll is the folder and Ribbon17 is the dll, obviously). I use # when necessary to avoid escape sequences. This string contains the exact assembly name needed, but Revit tells me "Assembly does not exist." If I replace this String variable with the hard coded C:\ProgramData\Autodesk\Revit\Addins\2017\AddInsAll\Ribbon17.dll it works. I want it obviously more robust than that. My code will be below, thanks in advance.
FYI: I have a TaskDialog showing when it first runs, and the fullPath that it returns is exacly the same as the hard coded path. I have to do a replace (Program Files to ProgramData) due to some weird bug with the get directory. Also, I add "\AddInsAll\Ribbon17.dll" to the end of the string because the CurrentDirectory goes only to Addins\2017. Finally, if you think the problem is due to the #'s, I have already tried putting it and taking it off of variables and none of the attempts work. But if you think of them is the problem, I welcome the advice. Thanks.
public class RibApp : IExternalApplication
{
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
{
// Create a custom ribbon tab
String tabName = "Add-Ins";
String fakeFullPath = #Directory.GetCurrentDirectory() + #"\AddInsAll\Ribbon17.dll";
String fullPath = fakeFullPath.Replace(#"\Program Files\", #"\ProgramData\");
TaskDialog.Show("Hi", #fullPath);
application.CreateRibbonTab(tabName);
//Create buttons and panel
// Create two push buttons
PushButtonData CommandButton = new PushButtonData("Command17", "Command",
#fullPath, "Ribbon17.Command");
I suggest you skip the # and replace each backslash \ by a forward slash /.
KISS!
Better still, use an approach similar to the CreateRibbonTab implementation in the HoloLens Escape Path Waypoint JSON Exporter.
I try to copy the EventLog "Application" to another folder on my PC but always get the error that
"....Could not find a part of the path
'C:\Windows\System32\winevt\Logs\Application.evtx..."
I use the code:
public void collectEventLogsFromSystem(string RequestedlogName,string newFolderPath)
{
string combinedLogToFind = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\" + RequestedlogName;
string LogEventsPath = (string)Registry.GetValue(combinedLogToFind, "File", null);
if (LogEventsPath != null)
{
System.IO.File.Copy(LogEventsPath, newFolderPath +"\\"+ RequestedlogName, true);
}
}//collectEventLogsFromSystem method
Even if i use explicit folder path it won't work:
System.IO.File.Copy(#"C:\Windows\System32\winevt\Logs\Application.evtx", "c:\\ttt\\Application.evtx", true);
any idea?
I found this answer on StackOverflow which will probably solve your problem. I have a 64 bit machine which exhibited the same behavior. This post by John Rasch solved the issue and explains why it failed.
If you are trying to get the log file while the program is running, the way above will not work. This post Export Event Log (.evtx) without "run as administrator" will allow you to backup the event log, even if you are currently using the event log in your application.
I have to save images to a folder located in "c:\inetpub\wwwroot\" and named as "UploadedImages". Here is my code:
public string SaveImage(string base64,int compno)
{
string res = "";
try
{
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
using (Bitmap bm2 = new Bitmap(ms))
{
bm2.Save(Server.MapPath("~/UploadedImages/ID"+compno+".jpg"));
}
}
res = "done";
}
catch (Exception ex) {
res = ex.ToString();
}
return res;
}
but it throws "A generic error occured in GDI+ at System.Drawing.Image.Save" exception. What am I doing wrong? This code works fine when saving image locally as
bm2.Save("D:Embasy\UploadedImages\ID"+compno+".jpg"));
What changes do I need to make to save images in localhost directory?
Your not going to believe this -- the site running v1.1 had a virtual directory set-up which was mapped to the directory in which the image was saved to -- things worked fine.
The v2.0 site also had the same virtual directory name, but the physical path was different -- I changed the path to point to the same directory as the v1.0 site and now the code works.
So in short -- you were right about the "path must exist".
Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components.
and kindly refer this link
http://msdn.microsoft.com/en-us/library/xs6ftd89.aspx
When you are using Server.Mappath
bm2.Save(Server.MapPath("~/UploadedImages/ID"+compno+".jpg"));
"~(tield)" : is point to project/application root folder c:\inetpub\wwwroot\yourproject
then find remaining your path /UploadedImages and then create ID1.jpg.
But your imagefolder "UploadImages" is exist in d: not in c:\inetpub\wwwroot\yourproject
if you want to exist your image folder in D: then you should to create
virtual directory and then you need to apply path as relevant
My problem actually was that every time i published website, I replaced the "UploadedImages" folder too and thus permissions were changed. So, i didnt replaced the folder again after changing its permissions and creating "everyone" group and giving full rights to it. Now code is working perfectly :)
I'm using configuration manager in the simplest way:
Read:
ConfigurationManager.AppSettings["Foo"]
Write:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Foo"].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
The problem is that after installing the application on different machines - some are looking for the file: "My.Application.exe.config"
while others look for "My.Application.config" (same, w/o the ".exe")
Another interesting detail is that after installing VS on the problematic machines - it works ok.
And my question is: Ah?!!?
Any ideas?
Thanks for the responses, your links were very helpful.
Since this is a .NET issue (as described in the links above), I tackled it from a different angle than suggested:
Since my configuration file is vast and demands both read and write operations, i'm using a special class to handle it - configurationFileHelper.
What I did was adding a static constructor to this class, in which i'm inquiring the expected name for the file, and, if necessary, renaming the existing file to match it:
static configurationFileHelper()
{
try
{
string fullFilename = Application.ProductName + ".exe.config";
string expectedFilename = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
if (!File.Exists(expectedFilename) && (File.Exists(fullFilename))
File.Move(fullFilename, expectedFilename);
}
catch { ; }
}
Hope this is helpful to someone...