Initialize DIR() function with HTTP server - vba

Hi the following line does not work if I run it after a PC reboot:
Filename = Dir("\\epocal-db-01\qa\docs\shared documents\17000001-*.xlsx")
but it does if I run this line first:
Set Wk = Workbooks.Open(Filename:="http://epocal-db-01/qa/docs/Shared Documents/17000001-00.xlsx", UpdateLinks:=0)
It sounds like a network mapping issue in my PC. Can I map the Http server without using the (slow) open method? Do I need to declare a library?
Thanks!

Related

Trying to run a Directory.Exists() with a system variable vs drive letter

I am trying to run a C# program to determine if a directory exists on multiple servers, so I need to run it as %system Variable%, rather than making a drive letter call, since not every server will have the same drive letter. This is what I have:
If My.Computer.FileSystem.DirectoryExists("D:\backup") Then
This code will work, as I define the drive
If My.Computer.FileSystem.DirectoryExists("%BCK_DRV%\backup") Then
This will not, I get my else error when running it. The %BCK_DRV% is defined in the environment variables, and I can navigate to the folder without issue using %BCK_DRV%\backup. Is there a special way to set and define a %drive% in C#?
Environment.GetEnvironmentVariable?
Code sample:
Dim backupDrive As String = Environment.GetEnvironmentVariable("BCK_DRV") & "\backup"
If My.Computer.FileSystem.DirectoryExists(backupDrive) Then
Try Environment.ExpandEnvironmentVariables():
string raw = #"%BCK_DRV%\backup" ;
string expanded = Environment.ExpandEnvironmentVariables( path_raw ) ;
Naturally, it's up to you to ensure that your process inherits the correct environment.
To expand "%BCK_DRV%\backup" to it's real value you need
Environment.ExpandEnvironmentVariables();
Example:
Environment.ExpandEnvironmentVariables("%winDir%\test")
will expand to "C:\Windows\test" (on my system).

Documentum DQL query to import a file form cliet machine to repository

Can anyone tell me how to import a document from client machine to documentum repository using only "DQL", below is the command I am using... it's not working thought...
The error I am getting is [DM_SYSOBJECT_E_CANT_ACCESS_FILE- Unable to access file due to operating system error.
CREATE abc OBJECT
set object_name='xyz',
set folder_title='pqr',
set doc_subtype_code='XXXX',
set template_code='00',
set doc_subtype_nme='abc Documents',
set isworkflowrequired=1,
set iscreatedfrombiztemplate=0,
set sec_classification_code='O',
set acl_domain='myacldomain',
set acl_name='myacl'
set product_wf_code='0'
LINK '/Cabinet123/MYDocs',
SETFILE 'C:\mydoc.doc' WITH CONTENT_FORMAT='msw8';
According to the documentation the file to upload using setfile must either be local to the Content Server or to network locations visible to the Content Server.

ASP Upload Component - Classic ASP

I have just moved a site from a dedicated server to a GoDaddy shared hosting account, and have just encountered loads of problems! One being with ASP Upload.
In Classic ASP, this is what I would normally do to upload files to my folder:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = Server.MapPath("../../files/photos/"&token_&"/")
upload.IgnoreNoPost = True
upload.Save(uploadPath)
Set upload = Nothing
But since moving to GoDaddy, I get this nasty message:
This feature has been disabled by the system administrator. Use SaveVirtual instead.
I went on to ASP Upload's website documentation and I could not find SaveVirtual, only SaveAsVirtual which is where I have become unstuck.
I tried using SaveAsVirtual but it threw an error stating that I was using a physical path and I should be using a virtual path! I really don't understand this and was hoping that somebody could put me straight. My website is now deemed broken and is offline, please help.
This is what I tried before the physical/virtual path error:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = Server.MapPath("../../files/photos/"&token_&"/")
upload.IgnoreNoPost = True
upload.SaveAsVirtual(uploadPath)
Set upload = Nothing
According to the docs, the method is named SaveVirtual. It does the Server.MapPath conversion for you.
So, try:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = "../../files/photos/"&token_&"/"
upload.IgnoreNoPost = True
upload.SaveVirtual(uploadPath)
Set upload = Nothing
You already set a folder path to upload not need use like this "server.mappath"
please use below of code.
Set Upload = Server.CreateObject("Persits.Upload" )
Upload.SetMaxSize 10000000 ' Maksimum dosya büyüklüğü Byte cinsinden
Upload.OverwriteFiles = True
Path = "../../duyurular/"
Count = Upload.SaveAsVirtual(Path)
for godaddy you have to go in and change the server folder permission to read/write. Otherwise you get that error message.
well I also get encounter with this problem, I just changed the folder privileges from Go-daddy Hosting server so Any one can read or Write file from specific location
Many Thanks
Ahsan Aziz Abbasi

Executable directory where application is running from?

I need to get the path (not the executable) where my application is running from:
System.AppDomain.CurrentDomain.BaseDirectory()
When I run the above statement with & "/images/image.jpg" on my local machine it works fine but when I install the application on another machine it says it cannot find the file and there is a lot of extra path information some.
I just need the directory of where the app is running. I am coding in VB.NET with Visual Studio 2008.
Thanks!
This is the first post on google so I thought I'd post different ways that are available and how they compare. Unfortunately I can't figure out how to create a table here, so it's an image. The code for each is below the image using fully qualified names.
My.Application.Info.DirectoryPath
Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath
AppDomain.CurrentDomain.BaseDirectory
System.Reflection.Assembly.GetExecutingAssembly.Location
System.Reflection.Assembly.GetExecutingAssembly.CodeBase
New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase)
Path.GetDirectoryName(Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path)))
Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path))
---
Edit October 18, 2021:
Sigh... None of the above work if using net5.0 or net6.0 and publishing app as single-file bundle. Best I got now is:
// This will give you the directory but not the assembly
string basedir = AppContext.BaseDirectory;
// Before you package the app as a single file bundle, you will get the dll.
// But after you publish it, you'll get the exe.
string pathToExecutable = Environment.GetCommandLineArgs()[0].Replace(".dll", ".exe");
Dim strPath As String = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
Taken from HOW TO: Determine the Executing Application's Path (MSDN)
I needed to know this and came here, before I remembered the Environment class.
In case anyone else had this issue, just use this: Environment.CurrentDirectory.
Example:
Dim dataDirectory As String = String.Format("{0}\Data\", Environment.CurrentDirectory)
When run from Visual Studio in debug mode yeilds:
C:\Development\solution folder\application folder\bin\debug
This is the exact behaviour I needed, and its simple and straightforward enough.
Dim P As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
P = New Uri(P).LocalPath
You could use the static StartupPath property of the Application class.
You can write the following:
Path.Combine(Path.GetParentDirectory(GetType(MyClass).Assembly.Location), "Images\image.jpg")

"The directory name is invalid" error on Process.Start?

I am writing a launcher program, and when I go to start the process I get the "The directory name is invalid" error. Here is the code that is launching the process:
Const DEBUG_ROOT = _
"Z:\Kiosk_JC\KioskSignIn.root\KioskSignIn\KioskSignIn\KioskSignIn\bin\Debug"
Dim oKiosk As New System.Diagnostics.Process
oKiosk.StartInfo.UserName = oEnc.Decrypt(Username)
oKiosk.StartInfo.Password = oEnc.DecryptSecure(Password)
oKiosk.StartInfo.Domain = oEnc.Decrypt(Domain)
''// The AddBS function appends a '\' to the passed string if it is not present
oKiosk.StartInfo.WorkingDirectory = AddBS(DEBUG_ROOT)
oKiosk.StartInfo.FileName = "KioskSignIn.exe"
oKiosk.StartInfo.UseShellExecute = False
Dim proc As Process = Nothing
proc = System.Diagnostics.Process.Start(oKiosk.StartInfo)
I saw on another question here that I needed to set the WorkingDirectory (before I started searching I was getting the error). Even though I have this property set, I am still getting the error. Any thoughts?
More info
I should also note that my Z:\ is a on my network. I have a function that resolves a path to UNC. When I ran this function on DEBUG_ROOT, I get the same error.
I tried moving the application to c:\kiosk. Same result. I am logged in as the user I am impersonating, so I have access to all shares and files.
Here is the link, for some reason the URL formating wants to consume all the text after the link is designated:
Referred Post
Mapped drives are per-user. You are likely starting the process with a different user.
Sounds like the process can't see the Z: drive or doesn't have security access. What user context does the app run under? Perhaps the Z: drive is not available in that context.
I got the same error as you do. most likely the user you use to run the process does not have access to specified resource (exe file)
try to move your exe to some other location and/or give your user access rights to the file.