I am trying to achieve a file lister, which will list all files in specified path. To do so I used mixture of panel, labels and File objects. The code to achieve this is as follow
label_songlist[i].Text=filename[i];
label_songlist[i].Height=25;
label_songlist[i].Location=new Point(x,y);
label_songlist[i].AutoSize=true;
label_songlist[i].Font=new Font(FontFamily.GenericSansSerif,10);
label_songlist[i].BorderStyle=BorderStyle.FixedSingle;
label_songlist[i].Padding=new Padding(0,0,0,5);
panel.Controls.Add(label_songlist[i]);
This works fine for first 5 file. After first five files it some how add space to left for remaining file giving output something like this
.
However, the value of x is never changed through out the execution of program. I did collect value of x and y for each label and wrote it to file. After execution I checked file. The value of X is 0. No change at all.
Related
So my question is basically, how do i start reading a file from a specific line, like for example line 14 until line 18?
Im working on a simple ContactList app and the only thing missing is deleting the information from a specific name. The user can create a new contact which has a name, a number and an address as information. I want the user to also be able to delete the data of that person by typing in their name. Then, the program should read the name and all of the 4 lines under it and remove them from the text File. How could i achieve this?
You can jump to any offset within a file. However, there isn't any way to know where a particular line begins unless you know the length of every line.
If you are writing a contact app, you should not use a regular text file unless:
You pad line lengths so that you can easily calculate the position of each line.
You are loading the entire file into memory.
You can't. You need to read the first n lines in order to find out which line has which number. Except if your records have a fixed length per line (which is not a good idea - there's always someone with a longer name that you could think of).
Likewise, you can't delete a line from the text file. The space on disk does not move by itself. You need an algorithm that implements safe saving and rearranges the data:
foreach line in input_file:
if line is needed:
write line to temporary_output_file
else:
ignore (don't write = delete)
delete input_file
move temporary_output_file to input_file
Disadvantage: you need about double the disk space while input_file and temporary_output_file both exist.
With safe saving, the NTFS file system driver will give the moved file the same time stamp that it had before deleting the file. Read the Windows Internals 7 book (should be part 2, chapter 11) to understand it in detail.
Depending on how large the contact list is (probably it's less than 10M entries), there's no problem of loading the whole database into memory, deleting the record and then writing everything back.
I am developing a Visual Studio extension in C# and I want to add classifications on a file based on an analysis of this file that is already provided. I have got analysis results with a set of locations (file, line, column) for each defect.
Based on MS doc, I have seen that we should implement the IClassifier.GetClassificationSpans method. I can see that we are given a set of SnapshotSpan. It looks like these spans are mostly complete lines from the open file: the visible lines currently shown and the line currently being edited.
However, as said previouly, I already have a set of defects with their location. I would like to get the current span line number so I can check I have got a defect registered on that line. I have browsed the whole SnapshotSpan structure with the debugger and I couldn't find anything looking the line number.
How to get current SnapshotSpan line number?
What is the logic of the framework when I already have results given with their location and I want to place glyphs/classifications/tooltips/outlining regions/etc in the editor based on these locations?
I finally found out that I can get the line number the following way:
var lineNumber= span.Snapshot.GetLineNumberFromPosition(span.Start.Position) + 1;
+1 because internal values start at 0 while visible lines in the editor start at 1 (or because my file analysis gives me lines starting at 1).
I use FileActivatedEventArgs args to do the file association in my video player app. So I when user double clicks a video file it opens and plays the file in my app, also it gets all the neighbouring files, so I can add them to playlist as well. I use following code for this purpose.
var file=args.Files[0];
StorageFileQueryResult neighboringFilesQuery=args.NeighboringFilesQuery;
var startingIndexunit = await neighboringFilesQuery.FindStartIndexAsync(file);
int startingIndex = Convert.ToInt32(startingIndexunit); //this is where exception occurs
not always but sometimes when I open a file I get a System.OverFlowException because the code tries to enter a very large garbage number into int32 which causes the exception.
After further investigation I have discovered that usually when I double click a file and get neighbor files, I get all the files in NeighborFilesQuery (including the 1 file I clicked to open) so I can just find its index so I can set the start index of my playlist in my app, and play the clicked file at correct position.
But in some other cases for example when I open a .flv or some a .rm file, I get all neighbor files in the neighborfilesQuery but I don't get the file I clicked, so when the code tries to get the index of that file, that file doesn't exist in that list hence I get a garbage index.
So why is this api so inconsistent? Sometimes it includes the clicked file in query files list, and sometimes it doesn't?
Note please note that I am only talking about a single file clicked scenario here and not about multiple files opened together (because in that case the files query is supposed to be empty and that is a different scenario).
According to the documentation, when FindStartIndexAsync, you should expect to see uint.MaxValue.
https://learn.microsoft.com/en-us/uwp/api/windows.storage.search.storagefilequeryresult.findstartindexasync
If we check the NeighboringFilesQuery documentation here: https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.fileactivatedeventargs.neighboringfilesquery, we see that it's not available for all invocations. We'll also notice that none of the mp4 files show in the NeighboringFileQuery, so when we activate by clicking on the mp4, the mp4 is still not in the NeighboringFileQuery list. When you call to get the index, it returns uint.MaxValue since the requested file is not in the query. The exception occurs due to an overflow when trying to convert this to Int32.
For this case, you'll want to check against uint.MaxValue prior to casting/converting to Int32. You should also catch any exception that might occur, since you'll get the overflow for any value greater than int.MaxValue.
In my current project, Aspose has been used to work with Excel file (XLXS). This excel file has 4 worksheets. First two sheets are empty except they have first row which contain column names. These tab got data through code and other two contains tons of complex formula based on these inputs. Just imagine first two tab as inputs, third tab as complex calculation and last tab as output. Average size of file ranges from 26MB to 48MB. Below piece of code does most of the work. After this method, the file has been saved in some physical location too. output date saved in DB. This process working fine so far with above range, but when size exceeded beyound 100MB, it started throwing Out of Memory exception. Hardly once or twice, it able to complete the process in around 80 - 100 mins.
public void CaclulateM(DataSet dataModel)
{
var workbook = this.ExcelModel.Workbook;
var ranges = ExcelModel.GetExcelModelRanges;
base.ImportInputsTo(workbook, ranges, dataModel);
workbook.CalculateFormula(false);
base.ExportOutputsTo(workbook, ranges, dataModel);
}
I tried out some of the solution provided by Aspose, but failed.I tried other dlls too including Interop, ExcelLibrary, NPOI, but same result.
https://forum.aspose.com/t/aspose-cell-dll-issue-for-xslb-file/164440
Please help or let me know if you need any other input to suggest anything. I cannot provide you the excel file due to confidentiality.
Okay, so I am making a game that reads data from a text file to create events. What happens is as each year advances if something exciting happens a popup box with three options appears, clicking them affects the game and so on.
I have created a function which can take various arguments and make the form automatically - so far so good- but writing large event descriptions in the code is messy and disorganized. Instead I decided to create another function which takes values from a text file, organizes them and then calls the second function to create the 'event'.
Now, as I said each event comes with three choices (See below) and each choice has a consequence on one of three factors (approval, prestige, power), I haven't quite worked out the mechanics properly but all in good time, everything runs wonderfully until I need to load this integers from the text file.
It keeps having trouble converting the string to an integer, why is this and how can I fix it?
Line 11 of the text file: 10 (yes I checked and it is the right line to read)
The code:
List<int> affecta = new List<int>();
affecta.Add(Int32.Parse(System.IO.File.ReadLines(filename).Take(11).First()))
I can load the other things such as the picture file's location perfectly, so 'filename' points to the correct .txt
It might be something really obvious to someone with more experience, but I just can't see why.
I don't think Take does what you think - It grabs the first 11 items and returns all of them, so you get an IEnumerable of 11 items. When you do First on that, you get item at position 0, not position 10. I think you want Skip and then First, which will skip the first 10 items and return the next (11th) item:
affecta.Add(Int31.Parse(System.IO.File.ReadLines(filename).Skip(10).First()))
If you use Take(11) this means "get 11 rows from the source". After that you have First(), so you'll get first of them. You're essentially trying to convert the first line into integer.
I assume you want to use Skip(10) since you want the 11th line.
Take(11).First() returns the First element from the IEnumerable containing the 11 elements.
Instead, Skip the first 10 and select the First from the IEnumerable.
affecta.Add(Int32.Parse(System.IO.File.ReadLines(filename).Skip(10).First()))
Alternatively, Take the first 11 and select the Last from the IEnumerable.
affecta.Add(Int32.Parse(System.IO.File.ReadLines(filename).Take(11).Last()))