C# Write to and read from txt file - readfile

Hallo! I have a specific question about my homework - C# window form app.
I enter data in text fields - first name, surname, last name, phone, email and date of birth (the last one is DateTimePicker control). And I save them with a button (
It's not actually saved at this stage, the data just goes to the other page of the app.)
Full names appear in ComboBox in other TabPage. When I select a name, I get the complete information about the person. I do that and it's works.(I'm using arrays).
The task done so far does not store any information. All input is lost when the application is closed.
The other part of the task gives me trouble - a link to an external text file in which the entered data is stored.
I create a text file and save information in it with this code :
private void button3_Click(object sender, EventArgs e)
{
TextWriter txt = new StreamWriter("D:\\data.txt");
for (int k = 0; k <= i; k++)
{
txt.Write(Names[k] + "\n" + Phone[k] + "\n" + Email[k] + "\n" + Birthday[k] + "\n");
}
txt.Close();
MessageBox.Show("Data saved in data.txt file on drive D!", "Caution!", 0);
}
And the problem is that I can't open and read the file to load the data back into the app.
I need to be able to load the full names in my ComboBox and when I select a name to see all the personal information about that person.
I attach file with my app - page1 and page2 and my text file with store data.
Thanks in advance to everyone who responds :)
And the problem is that I can't open and read the file to load the data back into the app.
I need to be able to load the full names in my ComboBox and when I select a name to see all the personal information about that person.

Related

using document library or form library

Sorry if my question is not good because I am new to sharepoint.
I have some document in document library I like to other people can come to library and put their comment there.
with using InfoPath designer form and repeated section and publishing form to form library I can data entry in the fields of InfoPath and upload attachment and then submit to form library and then other users can come and put their comment in the form.
now my problem is, my files are in document library and all meta data there is in document library. now my question is if I want to put comments on each Document i have to make a form library and again data entry all meta data in InfoPath form and upload attachments,....and then publish.
it seems it is a duplicate job, I like to know what is the best practice in this case?
I like to know I have to start with form library from scratch?
i note i am using sharepoint server 2013 and InfoPath from.
I think I found my answer in the below link address:
[Uploading File Attachment Into a Folder in a SharePoint Document Library Using InfoPath Form][1]
, with uploading InfoPath attachments in separate document library my problem will be solved. because i wanted my files in the document library folders and also can use features of InfoPath form with using repeated section.
now at first i use InfoPath from in form library and attach required files and then after submitting, the attaches files will be upload in document library of sharepoint.
also I found in the book (infopath with sharepoint 2013 how to) appendix B:
Appendix B. Upload File Attachments in Forms to a Document
Library
This appendix presents a code-behind method that uploads an attached file to a separate document
library when the form is submitted. The code here was adapted from Pranab Paul’s blog on MSDN.
Form Scenario
The form used in this scenario contains a file attachment control with a field named fileAttach. There
is also a button to be used as a submit button with and ID of SubmitButton.
The user may upload a file to the form and then submit the form. There is a form library in SharePoint
to which to submit the InfoPath form instance, but there is also a document library in which the file
attached to the form needs to be uploaded. A data connection for submission has been created and
points to the form library.
The form contains code-behind and therefore must have Full Trust. It also must be published as an
Administrator-Approved form and then added to Form Services in SharePoint.
Submit Button and Code-Behind Setup
The custom submit button needs to have a rule added such that when the button is clicked the Submit
Data action is executed. Also, in the button properties you need to click Edit Code to produce the
button event handler and method in the code-behind:
Click here to view code image
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["SubmitButton"]
).Clicked
+= new ClickedEventHandler(SubmitButton_Clicked);
}
public void SubmitButton_Clicked
(object sender, ClickedEventArgs e)
{
// Write your code here.
}
The code-behind project uses SharePoint functions and therefore needs a reference to the
Microsoft.SharePoint assembly. This is a similar requirement in the tracking changes solution
described in Chapter 17, “Track Changes in a Form,” so you may refer to those steps to include the
proper assembly reference in this file attachment solution.
Event Handler Code
Within the button event handler (SubmitButton_Clicked) you need code to perform the
retrieval of the attached file and the upload of that file to a document library. The code to perform this
is shown here:
Click here to view code image
public void SubmitButton_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator docXN = this.CreateNavigator();
XPathNavigator opnXN = docXN.SelectSingleNode("/my:myFields/my:fileAttach",
this.NamespaceManager);
byte[] attachmentNodeBytes = Convert.FromBase64String(opnXN.ToString());
// Position 20 contains a DWORD indicating the length of the
// filename buffer. The filename is stored as Unicode so the
// length is multiplied by 2.
int fnLength = attachmentNodeBytes[20] * 2;
byte[] fnBytes = new byte[fnLength];
// The actual filename starts at position 24...
for (int i = 0; i < fnBytes.Length; i++)
{
fnBytes[i] = attachmentNodeBytes[24 + i];
}
// Convert the filename bytes to a string. The string
// terminates with \0 so the actual filename is the
// original filename minus the last character !
char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);
string fileName = new string(charFileName);
fileName = fileName.Substring(0, fileName.Length - 1);
// The file is located after the header, which is 24 bytes long
// plus the length of the filename.
byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];
for (int i = 0; i < fileContents.Length; ++i)
{
fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
}
string SiteURL = "http://SharePointRoot/DocumentLibrary/" + fileName;
SPWeb site = new SPSite(SiteURL).OpenWeb();
site.Files.Add(SiteURL, fileContents);
}
Deployment
As mentioned earlier, you need to publish the form as an Administrator-Approved form and then
upload the form template to Form Services in SharePoint. Once you upload it to Form Services, you
may use the form as the content type in the desired form library.
When a new form is instantiated and submitted, the form instance is saved in the form library you
specified in the data connection for submission, and the attached file is stored in the document library
you specified within the code-behind

Pulling Drive activity report through GCP, is there a way to see folder path?

I am supposed to generate drive activity report so we can track what type of file users are using and where is the file being created (My Drive/shared drive).
I used the GAM command to pull drive activity report which has various fields except for the root path.
Does anyone know a way i can manipulate that so i can get a field that shows folder path as well.
Thanks!
You can try these particular GAM commands so you can edit them later to gather information of the folders and root folders:
gam user <User Email Address> print filetree depth 0 showmimetype gfolder excludetrashed todrive
You can edit the depth, for example orphaned folders when using -1. I am not familiar with which command you use, but you might need to mix or add some fields so it shows the root folder or path.
gam user <User Email Address> print filelist todrive select 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 showmimetype gfolder fields id
You might need to add over your command something like "print filetree" or "show filepath"
Reference:
https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files-Display
I have created a custom menu that iterates through a table of data, the data must have a column with the file IDs of interest and 2 additional columns for owner and path, since the file can be owned by either a user or a shared drive. The user running the function must have Super Admin rights to access files owned by other users and the user in question must be a member of a shared drive for the file to be located. My previous implementation as a custom function failed to address a limitation of this feature where advanced services are inaccessible.
The custom menu is created as explained in this documentation article https://developers.google.com/apps-script/guides/menus. There must be a trigger that executes when the sheet opens the menu is created.
In addition to that the code requires the use of Advanced Services, Google Drive must be added following the steps of this other article https://developers.google.com/apps-script/guides/services/advanced#enable_advanced_services. The advanced service will ask for authorization but the first time the code is executed. You may expedite the process by creating an empty function and running it.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('File ownership').addItem('Read data', 'readData').addToUi();
}
function readData() {
var sheetData = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
var i = 0;
for (; i < sheetData.length; i++){
if (sheetData[0][i] == '')
break;
}
SpreadsheetApp.getUi().alert('There are ' + i + ' cells with data.');
for (i = 1; i < sheetData.length; i++){
var fileID = sheetData[i][0];
var owner = getFileOwner(fileID);
var path = getFilePath(fileID);
SpreadsheetApp.getActiveSheet().getRange(i + 1,2).setValue(owner);
SpreadsheetApp.getActiveSheet().getRange(i + 1,3).setValue(path );
}
SpreadsheetApp.getUi().alert('The owner and file path have been populated');
}
function getFilePath(fileID, filePath = ""){
try {
var file = Drive.Files.get(fileID,{
supportsAllDrives: true
});
if (!file.parents[0])
return "/" + filePath;
var parent = file.parents[0];
var parentFile = Drive.Files.get(parent.id,{ supportsAllDrives: true });
var parentPath = parentFile.title;
if (parent.isRoot || parentFile.parents.length == 0)
return "/" + filePath;
else {
return getFilePath(
parentFile.id,
parentPath + "/" + filePath);
}
}
catch (GoogleJsonResponseException){
return "File inaccesible"
}
}
function getFileOwner(fileID){
try {
var file = Drive.Files.get(
fileID,
{
supportsAllDrives: true
});
var driveId = file.driveId;
if (driveId){
var driveName = Drive.Drives.get(driveId).name;
return driveName + "(" + driveId + ")";
}
var ownerEmailAddress = file.owners[0].emailAddress;
return ownerEmailAddress;
}
catch (GoogleJsonResponseException){
return "File inaccesible"
}
}
After executing the function, it will take significantly longer the more files IDs it has, the cells will be updated with their respective owner and path.
Note: with a Super Admin account you can programmatically create a view permission for shared drives you don't have access to using APIs or Apps Script, you may submit a separate question for more details or read the documentation in the developer page at https://developers.google.com/drive/api/v2/reference/permissions.

How to read word each page?

I know doc.Save() function save all page in one HTML file.
doc.RenderToScale() function save each page to the independent image file.
but i want read or save each page in independent HTML file,I had not idea,can you help me?
You can use the following code sample to convert each page to HTML or any other format supported by Aspose.Words.
String srcDoc = Common.DATA_DIR + "src.docx";
String dstDoc = Common.DATA_DIR + "dst {PAGE_NO}.html";
Document doc = new Document(srcDoc);
LayoutCollector layoutCollector = new LayoutCollector(doc);
// This will build layout model and collect necessary information.
doc.updatePageLayout();
// Split nodes in the document into separate pages.
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
// Save each page to disk as separate documents.
for (int page = 1; page <= doc.getPageCount(); page++)
{
Document pageDoc = splitter.getDocumentOfPage(page);
pageDoc.save(dstDoc.replace("{PAGE_NO}", page+""));
}
It depends on 3 other classes, which you can find in this zip file.
I work with Aspose as Developer Evangelist.

Excel VBA script or macro for linking to new Excel document using a template in it

I have a small family-operated shop and, in the process of speeding things up and/or automating them, I need help on the following matter (will try to explain as well as possible, since I am at a novice level on this kind of stuff.)
So, in my shop we offer a certain service (taking specific measurements of body dimensions along with weight/sugar levels etc etc). I have created an .xlsx document that contains all required fields and saved it as a template for future use. What I need to do is this:
I want to have a "master" Excel file with the names of our customers. From there, each name when clicked should open a new Excel file, using the aforementioned template, which would eventually be saved as each customer's record. I've tried a script for linking to the template but opening it as a new file (with the template in it) but, the problem is that each time I click on the name on the master file it opens a new document altogether, while I need it to open a new document named after the name in the original cell, with the template in it. As far as I can think, this is the best "automation" I can accomplish. Is it plausible? If so, how can I do it?
edit: this is the code, as i found it elsewhere:
'File:
' OfficeTemplate.vbs
'
'Problem:
' A hyperlink from an Office application to an Office template opens the template,
' instead of creating a new file.
' The proposed solution
' support.microsoft.com/kb/278627
' did not work.
'
'Solution:
' Create a hyperlink to a VBS file that starts the process.
'
'Instructions:
' Copy this VBScript into the same directory of your template.
' Rename it so that the VBS file name has the name of the template file in front.
' Example:
' Template name: test.dotx
' VBScript name: test.dotx.vbs
' Create the hyperlink to the VBS file.
Set fso = CreateObject("Scripting.FileSystemObject")
'Get the name of the template
OurName = fso.GetBaseName(WScript.ScriptName)
'Find all files in our directory
For Each File In fso.GetFolder(fso.GetParentFolderName(WScript.ScriptFullName)).Files
'Did we found the template?
If StrComp(OurName, File.Name, vbTextCompare) = 0 Then
'Invoke the default verb
CreateObject("Shell.Application").Namespace(0).ParseName(File.Path).InvokeVerb
'Wait a second to let the application start
WScript.Sleep 1000
'Done
Exit For
End If
Next
this is my template:
http://i215.photobucket.com/albums/cc55/psyclone_tread/templ.jpg
this is the master file, just a column with names and one with phone numbers, i want the names to link to each customer's individual file.
http://i215.photobucket.com/albums/cc55/psyclone_tread/master.jpg
Let me give you a very simple answer for this. Use VBA instead of VBS, and write code inside your master excel as per following illustration.
When you click on the cell with the name,
If File.Exists ("YourFolder\" & ActiveCell.Value & ".xlsx") Then
Workbooks.Open("YourFolder\" & ActiveCell.Value & ".xlsx")
Else
WorkBooks.Add(YourTemplate)
Fill in the details already present in the master sheet to new workbook if needed
NewWorkbook.Save("YourFolder\" & ActiveCell.Value & ".xlsx")
End If

Word automation with C++ Builder 5

I'm trying to control Word through a c++ builder 5 application. I would like to
open a ".dot" model file created with Word and modify it. In the ".dot" model file
there are some fields. For example, Title, LastName, FirstName, Address
and so on, and I would like to modify these fields putting text into them and then
saving file with a new name, for example "Warning.doc" leaving the ".dot" file
unaltered.
I can open the file, count the number of fields it contains, but then
when it comes to replacing each field with a string I don't know how to do because
I don't have a complete documentation on OleFunction and OlePropertyGet methods. I attach my source code to this message, can anybody help me to solve this problem please?
try
{
my_word = Variant::CreateObject("word.application");
}
catch (...)
{
Application->MessageBox("Unable to obtain Word automation object",
"Error:",MB_OK | MB_ICONERROR);
}
my_word.OlePropertySet("Visible", (Variant)true);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant this_doc;
Variant my_fields;
Variant test;
int k,field_count;
AnsiString test1;
AnsiString filename = "d:\\ProgrammaWord\\1-Avviso.dot";
my_docs = my_word.OlePropertyGet("Documents");
this_doc = my_docs.OleFunction("Open", filename);
my_fields = this_doc.OlePropertyGet("Fields");
field_count = my_fields.OlePropertyGet("Count");
for(k = 1; k <= field_count; k++)
{
test = my_fields.OleFunction("Item",(Variant)k);
test1 = test.OleFunction("Value"); //This instruction throws an exception
// "Value" is not a recognized parameter
// in this case
Memo1->Lines->Add(test1);
}
}
I never used word Ole but I used it for Outlook and Excel, I can't try it with word since I'm currently on OSX but you should try something similar as what I did.
The generic way of using Ole was to OleGetproperty() while you get the targeted field then OleSetProperty("action", ...).
for example when I wanted to change the color of the text in a particular cell of my excel document I used:
Variant _excel = Variant::CreateObject("Excel.Application");
Variant _workbook = _excel.OlePropertyGet("WorkBooks").OleFunction("Open", filename);
Variant _worksheet = _workbook.OlePropertyGet("WorkSheets", sheet);
_worksheet.OlePropertyGet("Cells", row, col).OlePropertyGet("Font").OlePropertySet("Color", color);
Here I instanciate an excel object, then I load a file into it (_workbook), then I select the _worksheet from the _workbook and I start my business.
Here comes the interesting part:
It concist of getting to a particular cell, getting the font object from it, and then setting the color of this font object.
Disclaimer: This is an example from my sources for excel, it's not directly related to your example, but maybe you can understand the principe with it. I can't try to figure out what you need because I have no windows right now.
Hope this can help you. Finding ressources for OLE can be fierce if you don't have the good patterns to look for.