Epicor C# Opening a Folder from a button - c#

I want to open a folder from a record pulled up in a form in Epicor. I have created a button and so far it opens up the root folder but I want it to go to a sub-folder with the record's name as the sub folder that will be created from SQL stored procedure when a new record is created.
Here is what I have so far:
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
string folder = "\\\\MasterServ\\Shared\\Customer Attachments\\";
Process.Start("IExplore.exe", folder);
}
I know something needs to be added at the end of the location to call the folder using the record but im not sure what.

When trying to get data out of a control in Epicor, generally speaking you want to go to the EpiDataView to get the value and not the control itself. There are multiple layers of abstraction going on in the form that make control handling wonky.
From your example for the comments I would do this. Code untested so hopefully I didn't make a typo.
EpiDataView edvUD104 = ((EpiDataView)(oTrans.EpiDataViews["UD104"]));
if (edvUD104.HasRow)
{
string folder = "\\\\MasterServ\\Shared\\Customer Attachments\\"
+ edvUD104.dataView[edvUD104.Row]["Key1"].ToString();
Process.Start("IExplore.exe", folder);
}
Edited for readability.

Related

Recent open files in RichTextBox [duplicate]

First of all I am a newbie in C# Programming, and I need to create a simple MRU as fast as i could.
Well the thing is I've tried looking at some online examples but however I found them to be quite a bit too confusing...
So is there anyway that anyone can create a "Recently Used" section in the toolstripmenuitem without going into those complicated codes??
E.g I will not be able to understand this stuff...
Registry key:
KEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\FileMRUList
Code:
Application.UserAppDataRegistry.DeleteSubKey("MRU", false);
RegistryKey appKey = Application.UserAppDataRegistry.CreateSubKey("MRU");
dictionary
microsoft.win32
I will only need something as simple as shown in this link below http://www.codeproject.com/KB/menus/MRUHandler.aspx
So you want to create a submenu like in the screenshot? For this, you will have to:
Store the list of recently-used files somewhere. This could be the registry, or it could just be a simple textfile, which I’ll do now to keep it simple.
Learn how to generate menu items at runtime instead of in the designer.
1. Store the MRU in a file
You will probably have already declared a private field to contain your MRU, right?
private List<string> _mru = new List<string>();
Every time someone opens a file, you add this file to the beginning of the MRU, right?
_mru.Insert(0, fullFilePath);
Now, of course when the application closes, you need to save this MRU to a file. Let’s do that in the Form’s FormClosed event. Double-click the FormClosed event in the properties and write some code which looks somewhat like this:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
File.WriteAllLines(mruFilePath, _mru);
Now we have saved the MRU in a file. Now obviously when the application starts, we need to load it again, so do something like this in the form’s Load event:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
if (File.Exists(mruFilePath))
_mru.AddRange(File.ReadAllLines(mruFilePath));
2. Create the menu items
Now that _mru contains the file paths that we want in our menu, we need to create a new menu item for each. I’ll be assuming here that you already have a menu item in the File menu (the item called “Most Recently Used” in your screenshot) and that it is called mnuRecentlyUsed, and that we only need to create sub-items:
foreach (var path in _mru)
{
var item = new ToolStripMenuItem(path);
item.Tag = path;
item.Click += OpenRecentFile;
mnuRecentlyUsed.DropDownItems.Add(item);
}
Now all we need is the method that actually opens a file, which I called OpenRecentFile:
void OpenRecentFile(object sender, EventArgs e)
{
var menuItem = (ToolStripMenuItem) sender;
var filepath = (string) menuItem.Tag;
// Proceed to open the file
// ...
}
Disclaimer
Please don’t use any of this code unless you understand it and you are sure that it is written to do what you intended. If it needs to do something slightly different, I’m sure you can make the necessary changes yourself.
Also, I’m sure you will have noticed that the above doesn’t update the sub-menu while the program is running. If you understand how the above code works, then I’m sure you’ll be able to figure out the rest for yourself.
http://www.codeproject.com/Tips/680088/Recent-Items-Tool-Strip-Menu-Item
This project does exactly what you want

Application setting doesn't work well

I have a checkbox(Name:tarahi_algouritm) and a button(Name:button1) on my form(Name:frm_choose).I want to save the latest changes on my checkbox as user clicked on the button.it means user run the program and check the checkbox and then click on button and then close the program.when he/she Rerun it,checkbox should be checked.or someway he disable the checkbox and click on button and after another run,checkbox should be disabled.
for this, in application setting(table part) put a checkbox (Name:s_tarahi_algouritm)and choose USER in scope part..as I said changes are apply on checkbox and s_tarahi_algouritm is used for save the latest changes on checkbox.I wrote these codes:
private void frm_choose_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.s_tarahi_algouritm!=null)
tarahi_algouritm= Properties.Settings.Default.s_tarahi_algouritm;
}
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.s_tarahi_algouritm = tarahi_algouritm;
Properties.Settings.Default.Save();
}
but When I make changes on checkbox and close the debug and Rerun it,changes are not applied.
what should I do?where is wrong?I am partly beginner so explain explicit.
thank you all
The problem is the settings files are written out in two parts: one to the application settings (which you can't save to) and the other to the user settings (which you can save to). You need to save the user settings (it gets written to your c:\users{userid}... directory).
Look at the most up-voted response to Farzin's link. It explains the issue as well.
Here's a more thorough explanation: App.config: User vs Application Scope
Here's an example.
I created a webform app and added a Settings file to it (called TestSettings.settings). I added two values:
When you run this application it creates a file in the application directory named the same as your executable with .config appended that contains (among other things) a element and a element. But this file only contains the initial values. If you change the value under the element and call Save() it will not update this file. It will create a file:
c:\Users{username}\AppData\Local{appname}{random_dir_name}{version}\user.config
My code to demonstrate this was:
Console.WriteLine(TestSettings.Default["UserValue"]);
TestSettings.Default["UserValue"] = "def";
TestSettings.Default.Save();
I tested many things like:
Properties.Settings.Default.Properties.Add(new System.Configuration.SettingsProperty("a"));
Properties.Settings.Default.Properties["a"].DefaultValue = "b";
Properties.Settings.Default.Save();
it has not error but do not save. In this link:
C# Settings.Default.Save() not saving?
Answered you must add Properties.Settings.Default.Reload(); after saving, I did that but not changed. It seems no one knows the answer.(I read many articles).
It looks like a cancer to me! I suggest you to easily save your settings to a xml file.
Below i add an easy xml saving method:
using System.Xml.Linq;
And
XElement settings;
try
{
settings = XElement.Load("settings.xml"); //beside the app .exe file
}
catch (Exception) // it is first time and you have not file yet.
{
settings = new XElement("settings");
settings.Save("settings.xml");
}
If you want to add new element:
settings.Add(new XElement("firstKey", tarahi_algouritm.Checked.ToString()));
settings.Save("settings.xml");
If you want to read or edit element:
XElement settings = XElement.Load("settings.xml");
string firstKey = settings.Element("firstKey").Value; //reading value
settings.Element("firstKey").Value = "New Value"; //Edit
settings.Save("settings.xml"); //Save
Remember that firstKey is only a name and you can use another names instead.

getting the full filenames from all top directory files in a specific directory and suppressing the occuring error

I met a not expected problem with getting just the top directory full filenames from a specific directory. C# throws an error and doesn't list anything in the specific directory.
But MS DOS has not a problem with my command: *"dir C:\windows\prefetch\*.pf"
Visual Basics 6 old "Dir Function" also does it without complaining.
The "Windows Explorer" opens it up and doesn't ask anything from me. Also "Nirsofts Tool Suit" lists it instantly without any problem. No one of this tools needs to run with special permissions, just a double click on the application icon and ready is the task.
I looked around and found nothing here, what would answer this weird problem. My user can access the directory, if I go with any other application into it, now there is the question why C# throws
an "Unauthorized Access Exception" which is totally weird, since I have access in this folder.
I don't want to elevate my application with admin permissions for it nor create extra a xml for it to run it with highest privileges. The not trustful yellow elevation box must be avoided.
Now my question: How it comes that I can not list the filenames in this folder when all other
applications can do that.
What code do I need if "Directory.GetFiles()" fails?
Is there any flag or property in the framework directory class which allows my application access to the files, whatever.
Here my code which fails (using System.IO):
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text.Substring(0, 0); //clear the textBox1
//Unauthorized access exception and yellow bar in this line
foreach(string FileX in Directory.GetFiles(Path.Combine(Environment.GetEnvironmentVariable("windir"), "prefetch"), "*.pf"))
{
textBox1.Text += FileX;
}
}
Did I understand correctly that you only need the File-names with directory-names.
This code works for me, no elevations needed.
private void button1_Click(object sender, EventArgs e)
{
string folder = #"C:\windows\prefetch";
string filemask = #"*.pf";
string[] filelist = Directory.GetFiles(folder, (filemask));
//now use filelist[i] for any operations.
}

Flajaxian Custom Folder Save Location

I see a lot of people coming up with some excessive ways to change the folder location on the fly with flajaxian multiple file upload control.
Was just wondering if the more experienced could take a look at the way I've come up with and let me know if there are any major issues I should be concerned about. (Assuming I have the proper error checking in place.)
I planned on initializing the control as seen below. :
<cc1:FileUploader ID="FileUploader1" runat="server" OnFileReceived="fileUploader_FileReceived" RequestAsPostBack="true">
</cc1:FileUploader>
(I RequestAsPostBack="true" as there are some other controls I need to check in my event handler)
I simply change the HttpFileCollection.SaveAs property in the fileUploader_FileReceived event. Since flajaxian does this one file upload at a time, we can expect that there is only 1 file in the collection (or else we could use a loop).
protected void fileUploader_FileReceived(object sender,
com.flajaxian.FileReceivedEventArgs e)
{
HttpFileCollection files = Request.Files;
// Change path to whichever folder I need
String TempFileName = "C:\\NEW\\PATH\\TO\\Folder\\" + files[0].FileName;
// Save the file.
files[0].SaveAs(TempFileName);
}
This implementation seems to work great as long as the folder is existing! I was just wondering if there is anything technically wrong with an implementation like this, again , assuming all error checking was in place.
Thanks!
A better way to do this would be to use an adapter, and over write the folder location in the
OnFileNameDetermining event. This way, we also get all the goodies with the adapter.
<cc1:FileUploader ID="FileUploader1" runat="server"` OnFileReceived="fileUploader_FileReceived" RequestAsPostBack="true">
<Adapters>
<cc1:FileSaverAdapter runat="server" FolderName="Ups" OnFileNameDetermining="fileUploader_FileDetermined" />
</Adapters>
</cc1:FileUploader>
In the file determined event, we can change the folder location programatically
protected void fileUploader_FileDetermined(object sender, com.flajaxian.FileNameDeterminingEventArgs e)
{
e.FileName = "C:\\NewFolder\\" + e.File.FileName;
}
We can use the FileReceived event to check if the folder exists, and if not, create it.
protected void fileUploader_FileReceived(object sender, com.flajaxian.FileReceivedEventArgs e)
{
int fileIndex = e.Index;
if (fileIndex == 0)
{
// We are on our first file, check if the new folder exists, if not, create it
}
}
What you are doing is fine, although, if you are saving files within the web site, consider using the MapPath method to create a physical folder from a virtual path within the web site
MapPath("/Images/User1")
This my mininal APSX implementation
<fjx:FileUploader ID="FileUploader1" runat="server" OnFileReceived="FileUploader2_FileReceived">
</fjx:FileUploader>
No adapters or folder is specified. When the FileRecevied event fires, I save files to a folder based on the Forms Authentication user name (names do not use characters not allowed in folder names).
Also note that the FileReceivedEventArgs has a reference to the (HTTP) file
e.File
The FileUploader control will show all files processed - you can even set the status code (e.g. 550) if there is an error, which is returned to the client.
Note that, the server call to the FileReceived event does not occur inside a nornal page postback, even if you specify
RequestAsPostBack="true"
So, a PagePreRender does not take place.
The only issue is, how do you perform any other processing at the client after the uploads complete (e.g. showing images uploaded).
Work I have in progress to this end is to use the client side event
FileStateChanged
When the last file is processed
if (file.state > Flajaxian.File_Uploading && isLast) {
I use JQuery to click a hidden submit button. The postback looks through session values stored when the files were saved, and renders back the images into a DIV.
However, an immediate submit causes issues with empty session inside the FileReceived event for some reason (I assume because the internal asynchronous call back has not completed). A pause of a few seconds before initiating the postback works OK.

How do I create a MRU in V 2010Express C# in the simplest way?

First of all I am a newbie in C# Programming, and I need to create a simple MRU as fast as i could.
Well the thing is I've tried looking at some online examples but however I found them to be quite a bit too confusing...
So is there anyway that anyone can create a "Recently Used" section in the toolstripmenuitem without going into those complicated codes??
E.g I will not be able to understand this stuff...
Registry key:
KEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\FileMRUList
Code:
Application.UserAppDataRegistry.DeleteSubKey("MRU", false);
RegistryKey appKey = Application.UserAppDataRegistry.CreateSubKey("MRU");
dictionary
microsoft.win32
I will only need something as simple as shown in this link below http://www.codeproject.com/KB/menus/MRUHandler.aspx
So you want to create a submenu like in the screenshot? For this, you will have to:
Store the list of recently-used files somewhere. This could be the registry, or it could just be a simple textfile, which I’ll do now to keep it simple.
Learn how to generate menu items at runtime instead of in the designer.
1. Store the MRU in a file
You will probably have already declared a private field to contain your MRU, right?
private List<string> _mru = new List<string>();
Every time someone opens a file, you add this file to the beginning of the MRU, right?
_mru.Insert(0, fullFilePath);
Now, of course when the application closes, you need to save this MRU to a file. Let’s do that in the Form’s FormClosed event. Double-click the FormClosed event in the properties and write some code which looks somewhat like this:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
File.WriteAllLines(mruFilePath, _mru);
Now we have saved the MRU in a file. Now obviously when the application starts, we need to load it again, so do something like this in the form’s Load event:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
if (File.Exists(mruFilePath))
_mru.AddRange(File.ReadAllLines(mruFilePath));
2. Create the menu items
Now that _mru contains the file paths that we want in our menu, we need to create a new menu item for each. I’ll be assuming here that you already have a menu item in the File menu (the item called “Most Recently Used” in your screenshot) and that it is called mnuRecentlyUsed, and that we only need to create sub-items:
foreach (var path in _mru)
{
var item = new ToolStripMenuItem(path);
item.Tag = path;
item.Click += OpenRecentFile;
mnuRecentlyUsed.DropDownItems.Add(item);
}
Now all we need is the method that actually opens a file, which I called OpenRecentFile:
void OpenRecentFile(object sender, EventArgs e)
{
var menuItem = (ToolStripMenuItem) sender;
var filepath = (string) menuItem.Tag;
// Proceed to open the file
// ...
}
Disclaimer
Please don’t use any of this code unless you understand it and you are sure that it is written to do what you intended. If it needs to do something slightly different, I’m sure you can make the necessary changes yourself.
Also, I’m sure you will have noticed that the above doesn’t update the sub-menu while the program is running. If you understand how the above code works, then I’m sure you’ll be able to figure out the rest for yourself.
http://www.codeproject.com/Tips/680088/Recent-Items-Tool-Strip-Menu-Item
This project does exactly what you want

Categories