IQdvEnvironment.GetQdvTempFileName Method
Parameters
- extension
- string
Optional. The extension (with or without a leading period) of the tmp file. The default value is ".tmp".
- filePrefix
- string
Optional. The prefix of the tmp file. The default value is "QDVtemp_".
- getAlternateTemp
- bool
Optional. If set to true, then ..USERNAME\Temp instead of AppData location is used. The former one is a trusted location, so you can execute files and open Office files without any restrictions. If set to false, the AppData location is used. The default value is false.
Return Value
stringException type | Condition |
---|---|
A problem occurred. |
You can use this method to create any tmp files. For example, if you don't want to work on an original estimate file, you can create a tmp copy and work with it safely.
The advantage of this method is that there's no need to delete these tmp files. They are automatically deleted when QDV main application is closed. Of course, this is only done when called from a macro in which case QDV is running. If called from an external client, the files will be cleaned only when QDV is launched and then closed.
The following example creates a temporary copy of an estimate file, opens the estimate from that copy and reads some data. This will prevent from any accidental changes in the original file and more importantly, it prevents problems if the estimate is already opened (and thus locked). When everything is finished, the estimate is closed.
' The following code will inspect specified estimate. We don't want to modify the estimate, ' we only need to read some info from it. In such a case it is safer to open it in "read-only" mode. ' This is done by creating a tmp copy of the file and working with it. ' The file name of the estimate to be inspected. Dim estimateFileName As String = "C:\Sample_1.qdv" Dim estimate As IEstimate = Nothing ' Use IQdvEnvironment to get a tmp path. Dim tmpFileName As String = Context.QdvManager.Environment.GetQdvTempFileName(".qdv", "readonly_copy_") ' The tmpFileName is something like C:\Users\<USER>\AppData\Local\Temp\QDVTempFilesMain\readonly_copy_kqcc1fp5.qdv. Try ' Create a tmp copy of the estimate file. This will prevent from any changes in the original file ' and more importantly, it prevents problems if the estimate is already opened (and thus locked). If System.IO.File.Exists(estimateFileName) Then System.IO.File.Copy(estimateFileName, tmpFileName, True) End If ' Remove the read-only protection, if it was applied. Can happen if the original file had the read-only attribute. Dim attributes As System.IO.FileAttributes = System.IO.File.GetAttributes(tmpFileName) attributes = attributes And Not System.IO.FileAttributes.ReadOnly System.IO.File.SetAttributes(tmpFileName, attributes) ' Get the estimate instance with IEstimateFactory. estimate = Context.QdvManager.EstimateFactory.GetEstimate(tmpFileName) ' Get required data from the estimate. For example, get the number of all tasks. Dim taskCount As Integer = estimate.CurrentVersion.Wbs.GetTasksForScope("", True).Count MessageBox.Show("The number of tasks in the inspected estimate is " & taskCount) Finally ' When everything is done, don't forget to close the estimate. If estimate IsNot Nothing Then estimate.Close() End If ' There's no need to delete the tmp file created with GetQdvTempFileName ' because it is done automatically when QDV application is closed. End Try
This language is not supported or no code example is available.