|
You may use Directory.GetFiles(dirname) to get all the files from dirname location. Then loop through returned files and call your code.
Calin
|
|
|
|
|
|
something like this, you should review it because you know what exactly to read from console,...:
...
foreach(string inFile in Directory.GetFiles(filePath))
{
...
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
Console.WriteLine();
Console.WriteLine("Successful file open!...");
Console.WriteLine();
Console.WriteLine("Input file name to save!");
Console.WriteLine("sample: d:\\filename.txt");
filePath = Console.ReadLine();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
List lines = new List();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
int numberOne = Int32.Parse(lines[0]);
int numberTwo = Int32.Parse(lines[1]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberTwo + numberThree;
sw.WriteLine(x);
}
catch { }
sw.Close();
sr.Close();
}
Calin
|
|
|
|
|
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile, filePath;
string line;
foreach (string inFile in Directory.GetFiles(filePath))
{
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
Console.WriteLine();
Console.WriteLine("Successful file open!...");
Console.WriteLine();
Console.WriteLine("Input file name to save!");
Console.WriteLine("sample: d:\\filename.txt");
filePath = Console.ReadLine();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
int numberOne = Int32.Parse(lines[0]);
int numberTwo = Int32.Parse(lines[1]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberTwo + numberThree;
sw.WriteLine(x);
}
catch { }
sw.Close();
sr.Close();
}
}
}
</string></string>
Error:
<br />
Error:<br />
A local variable named 'inFile' cannot be declared in this scope because it would give a different meaning to 'inFile', which is already used in a 'parent or current' scope to denote something else <br />
|
|
|
|
|
Of course...you had to remove first inFile line, because now you are not reading the input file from console.
I just sent you the main idea about how the cose should be changed. Its your task to finish it.
Calin
|
|
|
|
|
this code is only working for a txt files but I want to apply all txt files in a folder its
|
|
|
|
|
problem solved
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile;
string line;
const string inDir = "D:\\data\\A\\";
const string outDir = "D:\\data\\B\\";
DirectoryInfo di = new DirectoryInfo(inDir);
FileInfo[] files = di.GetFiles("*.txt");
foreach (FileInfo fi in files)
{
inFile = fi.FullName;
StreamReader sr = File.OpenText(inFile);
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
int numberOne = Int32.Parse(lines[0]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberThree;
sr.Close();
string destFile = Path.Combine(outDir, fi.Name);
File.WriteAllText(destFile, Convert.ToString(x));
}
}
}
</string></string>
|
|
|
|
|
Hi guys,
I have a winform with a public datagridview(dgv1) with some combobox columns.
from a another form i can see the dgv1, but not the columns that i have created into it.
What's that means?
Thanks
|
|
|
|
|
Make sure you have GenerateMember = true and Modifiers = Public for each column.
Calin
|
|
|
|
|
Hi,
I want to write a Sharepoint web service that will run on my Windows Server 2003 as that's what Sharepoint will run on.
I want to write the WS on my local machine which is running VS 2005 on XP and then deploy it to my server. It seems that I need to reference the Sharepoint assembly in my project but I can't install Sharepoint Services 3.0 on my XP machine can I? And that means I can't install the VS 2005 extensions for Sharepoint either.
Do I *have* to do my development on the server itself or what? I'd rather not have to install VS 2K5 on the server just to write one simple WS.
|
|
|
|
|
You can use the sharepoint webservices instead of the object model, or develop on a server OS. You can't use the sp object model on XP.
I didn't get any requirements for the signature
|
|
|
|
|
Thanks for your reply
I can just reference the web service on the server then?
My server is running as a VM on the same machine with a bridged network.
How can I include the following in my project then?
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
|
|
|
|
|
|
DUDE! You can't show people where the documentation is, it's a secret! Imagine what would happen to these and other forums if developers started using Google to find and then read documentation!
|
|
|
|
|
Shut it you! I'm gonna join your geeky club if it kills me
|
|
|
|
|
|
Thanks - I'm trying to follow an example in a book and I was dreading what it meant, that I'd have to install VS2K5 on the OS VM
Ah well
|
|
|
|
|
Hi, i have two function:
long ImageFileOpen (long *hImageFile, char *szFileName, long bWrite)
Parameters:
hImageFile
Image file handle is returned here.
szFileName
File name of the image file.
bWrite
0 = open file for reading, 1 = open file for writing.
and
long ImageFileRead(long hImageFile, long *hImage)
Parameters:
hImageFile
Image file handle that was created by previous call to ImageFileOpen.
hImage
Image handle of a new image is returned here.
i have called them in this way:
[DllImport("xxx.dll")]
unsafe public static extern long ImageFileOpen(long* hImageFile, [MarshalAs(UnmanagedType.LPStr)] StringBuilder szFileName, long bWrite);
[DllImport("xxx.dll")]
unsafe public static extern long ImageFileRead(long hImageFile, long* hImage);
and then with:
long hImageFile=0;
long hImage=0;
StringBuilder fullname = new StringBuilder(@"c:\xxx.tif");
rc = ImageFileOpen(&hImageFile, fullname, 0);
rc = ImageFileRead(hImageFile, &hImage);
...but at ImageFileRead the compiler says "System.AccessViolationException".
why? thank you very much...I need help...
Alessio
|
|
|
|
|
Hi,
I would try that differently:
1.
in this situation there is no need for pointers and unsafe keyword, just use the IntPtr class (it takes 4 or 8 bytes depending on Win32/Win64).
2.
read-only strings can be passed to a char* as is; a StringBuilder is required only if the native code needs to provide or modify the string value (use a StringBuilder.ToString when done).
3.
an output parameter needs the out (or ref) keyword; that basically takes care of the indirection,
i.e. the variable gets then passed by reference automatically.
4.
warning: in C# long takes 8 bytes, in the native world long usually is 4 B.
So I would try this:
[DllImport("xxx.dll")]
public static extern long ImageFileOpen(out IntPtr hImageFile, string szFileName, bool bWrite);
[DllImport("xxx.dll")]
public static extern long ImageFileRead(IntPtr hImageFile, out IntPtr hImage);
IntPtr hImageFile;
IntPtr hImage;
rc = ImageFileOpen(out hImageFile, fullname, false);
if (rc...) ...
rc = ImageFileRead(hImageFile, out hImage);
Now the tricky part could be what comes next: how will managed code access the content of the image?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:15 AM
|
|
|
|
|
ty very much Luc....it's work.....
so the problem was the indirection? And the out takes care of it? So i don't have to use a fixed *.
|
|
|
|
|
Now the tricky part could be what comes next: how will managed code access the content of the image?
:)
Can I answer?
System.Drawing.Image.FromHbitmap
|
|
|
|
|
Mirko1980 wrote: Image.FromHbitmap
Sure, but then why the native detour, why not just Image.FromFile(), that does accept TIFF files doesn't it?
Unless something tricky is going on in the native read function, I was expecting the OP to be interested in parts of the image file, not the entire image.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:15 AM
|
|
|
|
|
Hello!
I've been having some issues with masked textboxes and have been unable to find a solution, so I hope one of you knowledgeable forumers can point me in the right direction.
Let's say for example I have a masked textbox and I want to restrict it to a 4digit numeric-only ID#. The Mask is set as "0000" and the PromptChar is "_". My problem arises when I run the project and enter the textbox. The | is placed at the end of the Prompt "____" and in order to input the data I want properly I need to backspace, key over, or click to the beginning of the string.
How can I have a masked textbox always place the data entry marker (what's it called?) at the beginning of the Prompt string when the textbox becomes the selected control?
Any help would be hugely appreciated. Thanks in advance!
|
|
|
|
|
use the SelectionStart property to set the position of the cursor (with nothing selected)
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
It baffles me why this property isn't actually IN the properties list for masked textboxes! Thanks william. Am I going to have to use an Enter event for every masked textbox in order to do this?
|
|
|
|