PutFile() Method - dFPUG-Portal



|Visual FoxPro Toolkit for .NET | |

PutFile() Method

Calls the Save As dialog box and returns the file name you specify. (Please note that not all the parameters are implemented.)

[pic]

This method is only available in WinForms and not available for WebForms.

[Visual Basic]

Public Shared Function PutFile(ByVal tcTitle As String, ByVal tcFileName As String, ByVal tcExtension As String) As String

Public Shared Function PutFile() As String

Public Shared Function PutFile(ByVal tcTitle As String) As String

Public Shared Function PutFile(ByVal tcTitle As String, ByVal tcFileName As String) As String

[C#]

public static string PutFile(string tcTitle, string tcFileName, string tcExtension)

public static string PutFile()

public static string PutFile(string tcTitle)

public static string PutFile(string tcTitle, string tcFileName)

Example

[Visual Basic]

PutFile("Save Custom File As", "MyCustomFile", "abc;def;kam")

PutFile()

PutFile("Save Custom File As")

PutFile("Save Custom File As", "MyCustomFile")

[C#]

VFPToolkit.dialogs.PutFile("Save Custom File As", "MyCustomFile", "abc;def;kam");

VFPToolkit.dialogs.PutFile();

VFPToolkit.dialogs.PutFile("Save Custom File As");

VFPToolkit.dialogs.PutFile("Save Custom File As", "MyCustomFile");

Implementation

[Visual Basic]

Public Shared Function PutFile(ByVal tcTitle As String, ByVal tcFileName As String, ByVal tcExtension As String) As String

'Initialize the return file name

Dim lcFileName As String = ""

Dim lcFilter As String = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

'Open the save as dialog for the user to select a file

Dim sfd As SaveFileDialog = New SaveFileDialog()

sfd.RestoreDirectory = True

sfd.InitialDirectory = System.IO.Directory.GetCurrentDirectory()

sfd.FileName = tcFileName

'Specify the default filter to use for displaying files

If tcExtension.Trim().Length = 0 Then

sfd.Filter = lcFilter

sfd.FilterIndex = 2

Else

Try

sfd.Filter = lcFilter + VFPToolkit.dialogs.__GetExtenstion(tcExtension)

sfd.FilterIndex = 3

Catch

sfd.Filter = lcFilter

End Try

End If

'check if a title is specified

If tcTitle.Trim().Length > 0 Then

sfd.Title = tcTitle

End If

'Show the dialog and if the user selects a file return the file name

If sfd.ShowDialog() DialogResult.Cancel Then

lcFileName = sfd.FileName

End If

'return the file name

Return lcFileName

End Function

Public Shared Function PutFile() As String

Return PutFile("", "", "")

End Function

Public Shared Function PutFile(ByVal tcTitle As String) As String

Return PutFile(tcTitle, "", "")

End Function

Public Shared Function PutFile(ByVal tcTitle As String, ByVal tcFileName As String) As String

Return PutFile(tcTitle, tcFileName, "")

End Function

Private Shared Function __GetExtenstion(ByVal lcExtension As String) As String

Dim laSeperators() As Char = {";"c, "|"c}

Dim laExtensions() As String = lcExtension.Split(laSeperators)

Dim sb As StringBuilder = New StringBuilder()

Dim lcCurrent As String

Dim lcPrevious As String = ""

Dim i As Integer

For i = 0 To laExtensions.Length - 1 Step i + 1

'Check if the extension has a period and if so then do not add a *

lcCurrent = laExtensions(i).Trim()

' Check if there is an open parenthesis in this line and if so then

' simply store then one and pick up the next one

If (lcCurrent.IndexOf("(") >= 0) And (lcPrevious.Length = 0) Then

lcPrevious = lcCurrent

Else

'If there is no period in this extension then add one

If lcCurrent.IndexOf(".") < 0 Then

lcCurrent = "*." + lcCurrent

End If

'Create the extension

If lcPrevious.Length = 0 Then

sb.Append("|" + lcCurrent)

sb.Append("|" + lcCurrent) 'append it twice

Else

sb.Append("|" + lcPrevious)

sb.Append("|" + lcCurrent)

End If

'reset the previous string

lcPrevious = ""

End If

Next

Return sb.ToString()

End Function

[C#]

public static string PutFile(string tcTitle, string tcFileName, string tcExtension)

{

//Initialize the return file name

string lcFileName = "";

string lcFilter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

//Open the save as dialog for the user to select a file

SaveFileDialog sfd = new SaveFileDialog();

sfd.RestoreDirectory = true;

sfd.InitialDirectory = System.IO.Directory.GetCurrentDirectory();

sfd.FileName = tcFileName;

//Specify the default filter to use for displaying files

if(tcExtension.Trim().Length == 0)

{

sfd.Filter = lcFilter ;

sfd.FilterIndex = 2;

}

else

{

try

{

sfd.Filter = lcFilter + VFPToolkit.dialogs.__GetExtenstion(tcExtension);

sfd.FilterIndex = 3;

}

catch

{

sfd.Filter = lcFilter ;

}

}

//check if a title is specified

if(tcTitle.Trim().Length > 0)

{

sfd.Title = tcTitle;

}

//Show the dialog and if the user selects a file return the file name

if(sfd.ShowDialog() != DialogResult.Cancel)

{

lcFileName = sfd.FileName;

}

//return the file name

return lcFileName;

}

public static string PutFile()

{

return PutFile("", "", "");

}

public static string PutFile(string tcTitle)

{

return PutFile(tcTitle, "", "");

}

public static string PutFile(string tcTitle, string tcFileName)

{

return PutFile(tcTitle, tcFileName, "");

}

private static string __GetExtenstion(string lcExtension)

{

char[] laSeperators = {';','|'};

string[] laExtensions = lcExtension.Split(laSeperators);

StringBuilder sb = new StringBuilder();

string lcCurrent ;

string lcPrevious = "";

for(int i=0; i< laExtensions.Length; i++)

{

//Check if the extension has a period and if so then do not add a *

lcCurrent = laExtensions[i].Trim();

// Check if there is an open parenthesis in this line and if so then

// simply store then one and pick up the next one

if((lcCurrent.IndexOf("(") >= 0) && (lcPrevious.Length == 0))

{

lcPrevious = lcCurrent;

continue;

}

if(lcCurrent.Length == 0)

lcCurrent = "*";

//If there is no period in this extension then add one

if(lcCurrent.IndexOf(".") < 0)

lcCurrent = "*." + lcCurrent;

//Create the extension

if(lcPrevious.Length == 0)

{

sb.Append("|" + lcCurrent);

sb.Append("|" + lcCurrent); //append it twice

}

else

{

sb.Append("|" + lcPrevious);

sb.Append("|" + lcCurrent);

}

//reset the previous string

lcPrevious = "";

}

return sb.ToString();

}

Requirements

Namespace: VFPToolkit

Class: VFPToolkit.dialogs

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family

Assembly: VFPToolkit (in VFPToolkitNET.dll)

See Also

VFPToolkit.dialogs Members | VFPToolkit Namespace

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download