|
Unless you expect your file to be yuuge, you probably don't need a streamreader. File.ReadAllText would do, and that would return a string. Split it on characters #10 and #13 (CR LF) and you'll have an array of lines.
You'll have to "find" the appropriate entry by looking at those strings.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks - that is ok for me, all i need to know is how to use the file that i double-clicked. That is not clear to me ... the app start when i double-click on it, but how can i access the textfile (what is needed that the app knows it is opened by a textfile and parse the values). I read actual about
Environment.GetCommandLineArgs(); but unfortunately it seems to be empty 
|
|
|
|
|
I'd prefer to get the command-line arguments as passed into the main-method[^], but it should yield the same result.
It is an array of which the first item may be empty. If no arguments are supplied at all, then you probably did not register the correct command to launch the application. Did you include a "%1" in the command-line as registered to launch the application?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i found my error. The extension does not open with my exe file. Instead it opens with the ClickOnce Handler .... now i have to find out how to change this
When doing it right i get the filename and path that opens my app so i can continue from here i think.
Thanks for everybody!
|
|
|
|
|
Or let the system do it for you with File.ReadAllLines
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Lines! You're right!
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have an interface I need to implement. But one of the interface's members I cannot understand why the refactor in VS implement in a certain way.
Here is the interface. (Never mind the names for variables etc, I have changed them).
using System;
public interface IStuff
{
void SPB(string a, DateTime d, string c);
void P(decimal a, string r);
void EPB();
}
I have a class Stuff which implement the interface. Here is how VS implemented the interface for me.
using System;
namespace Namespace1
{
public class Stuff : IStuff
{
public void SPB(string a, DateTime d, string c)
{
}
public void IStuff.P(decimal a, string r)
{
}
void EPB()
{
}
}
}
What I don't understand is why the P() method in the interface is implemented in the class as:
public void IStuff.P(decimal a, string r)
{
}
Why not like this?
public void P(decimal a, string r)
{
}
Why is this so? How do I access the P() method in the class?
What is going on here?
|
|
|
|
|
Check the rest of your Stuff class - you already have some object called "P" so VS inserts an explicit implementation "IStuff.P" so that there is no confusion.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks Griff!
My original class was named "P" as well *lol* Therefore VS inserted the explicit implementation.
I renamed the class to something else and I got the correct interface implementation.
/Steffe
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Mc_Topaz wrote: public void IStuff.P(decimal a, string r)
void EPB()
When you changed the method names for your post, you also changed the access modifiers on your methods. The code you've posted won't compile.
You'd need to remove the public from P , and add it to EPB instead:
void IStuff.P(decimal a, string r) { ... }
public void EPB() { ... }
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Everything declared in an Interface, when you implement it in a class, must have the access modifier 'public. This "default" implementation syntax can be called implicit implementation.
The exception, which does confuse people, is the special case where you have a class that implements more than one Interface and identical names are used in each Interface, and you need to make it clear, for a duplicated name implementation, which Interface your implementation refers to.
So, when explicit implementation is used: no modifiers are allowed; and, the Interface name is followed by a dot, and the declaration.
The examples here should make this clear: [^].
If you are one of those curious persons who dares ask why you can't have access modifiers in Interfaces, and/or why you can't use other modifiers than 'public in your implementation of Interfaces; you may wish to read this thread: [^].
Suppose your class implements one Interface, and you make every implementation explicit:
public interface IStuff
{
void SPB(string a, DateTime d, string c);
void P(decimal a, string r);
void EPB();
string Name { set; get; }
}
public class Test : IStuff
{
void IStuff.SPB(string a, DateTime d, string c)
{
throw new NotImplementedException();
}
void IStuff.P(decimal a, string r)
{
throw new NotImplementedException();
}
void IStuff.EPB()
{
throw new NotImplementedException();
}
private string _name;
string IStuff.Name
{
get { return _name; }
set { _name = value; }
}
} When you create an instance of this class, none of its methods, and its one field, can be accessed from the instance: you'll have to cast the instance to the Interface:
var test = new Test();
(test as IStuff).name = "wtf ?";
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 18-Jan-17 2:48am.
|
|
|
|
|
Hi there everyone, new here and would like to get some feedback on my code.
I run a store procedure that I want to dump on a excel template.
It currently works, but just takes way too long. On sql management studio the query runs good, but just writing to the template is really slow.
Can anyone suggest a more efficient way to achieve the same result?
thanks in advance
here is part of my code:
sdate = StartDate.Value.ToString();
edate = EndDate.Value.ToString();
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet aSheet;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;
//open the excel template
oWB = oXL.Workbooks.Open("C:\\TEMP\\template.xlsm");
//oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
//Call to service
//aSheet = (Excel._Worksheet)oWB.Worksheets.get_Item(1);
aSheet = (Excel._Worksheet)oWB.ActiveSheet;
//backgroundWorker1.ReportProgress(i++);
writedata_from_proc(aSheet, "dbo.CODE_RED_2017");
//backgroundWorker1.ReportProgress(i++);
//Make sure Excel is visible and give the user control
//of Microsoft Excel's lifetime.
//backgroundWorker1.ReportProgress(i++);
MessageBox.Show("Data extraction complete");
oXL.Visible = true;
oXL.UserControl = true;
//SaveExcel(oWB);
//clean up the COM objects to remove them from the memory
Marshal.FinalReleaseComObject(aSheet);
Marshal.FinalReleaseComObject(oWB);
Marshal.FinalReleaseComObject(oXL);
}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
MessageBox.Show(errorMessage, "Error");
}
}
|
|
|
|
|
It's slow because you're using Office Interop to create the Excel workbook. Office Interop is notoriously slow and there's no way you can speed this up.
To get it to go faster, you have to drop Excel and use the OpenXML SDK to create an Excel workbook file directly. It's much faster but the learning curve to use the SDK is kind of steep.
|
|
|
|
|
You can also export the data to a tab or comma separated text file - Excel is happy to use them
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
If it's straight data, yeah, that works. If he's formatting it, not so much.
|
|
|
|
|
It doesn't matter how much you format it, the bean counters will always change it so that it looks totally different, because they are all "Excel experts"!
In the sample code in the question it is just straight data - no formatting or formulae.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
|
Yeah, by careful who you reply to. I got a notification that you replied but the OP didn't.
I know about ClosedXML.
|
|
|
|
|
|
You may want to try EPPlus-Create advanced Excel spreadsheets on the server - Home[^]
Works quite well.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Hi all
I am beginner with C# programming. I have a problem with Teleric split button. I want to have the index number (or value) of menu item in split button. please help me.thanks.
|
|
|
|
|
Member 12938797 wrote: I am beginner with C# programming
Then you get familiar with reading the documentation that came with the control suite. If you still can't figure it out, ask the support people. You paid for the controls you also pay for support and they are the most familiar with their library than random strangers on the internet. You can contact them here Support and Learning | Telerik[^]
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
the the "defaultitem" property is used for this case. I need a code to learn how to use this property.
|
|
|
|
|
Member 12938797 wrote: I need a code to learn how to use this property
Then do what I already told you to do and read the documentation. If you still can't figure it out, go to the Telerik website and ask them your question. We aren't a "write code for me" website.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|