[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Severside text file access

Posted on 2004-04-07
10
Medium Priority
?
227 Views
Last Modified: 2010-04-05
Hi

     I'm currently planning a server side project in which I would need to access txt files on the server, however I am unsure quite how to go about this, and so have a few questions:

    Is it possible to write to the txt file when it’s on the server where would it be best to place them? Do I need to change the    
   Files access rights?
    If so what would the path to a text file be? Obviously not C:\mytextfile.txt would it be something like    
      www.mysite.com/mytextfile.txt??
    How do I cope with simultaneous access requests, I really have no idea...
    Anything else I should consider?

  I would be happy building the project either as a Dll or a CGI exe in your expert opinions would be easier in light of the above, especially dealing with simultaneous access requests

Thanks in advance

David
0
Comment
Question by:DavidBirch2dotCom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 10782353
Hi,

If your app is an ISAPI or CGI app on a server (obviously accessed via Internet browser) and the text file is on the same server then your app accesses the file as a local file, i.e. c:\mytextfile.txt.

If the file is on another computer in the same LAN where the server is then the folder (where the file is in) should be shared and your app can access it using a mapped drive or UNC name (\\SecondServer\SharedFolder\mytextfile.txt).

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 10782359
BTW I personally prefer CGI exe instead of ISAPI dll.
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10782369
Thanks,

I would be deploying the project onto a shared webserver for use on my website, so I doubt I would be able to access the C drive

Would I be able to write to the text file if it was at www.mysite.com/mytextfile.txt? 

How would I cope with simultaneous access requests? Does CGI exe make this easier?

David
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:geobul
ID: 10782633
Does your CGI app see any local file system? Can you use a static html page (a file stored somewhere on the server) and send that page as a response from your CGI?
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10798050
Yes im testing the app on PWS on my computer, it will access the file if i give the right address eg C:\Mytxt.txt but not if i go
Webserver/Scripts/Mytxt.txt  ??? am i giving the address wrong? what should it be? i very much doubt i would be able to access the C drive on the server so I really need an answer.

David
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10806038
ok ive found some code that might do what i want, i found this on the following site http://www.nickhodges.com/Delphi/Articles/DL180/dl180.htm#HTML%20From%20an%20Existing%20File

HTML From an Existing File
 This next example is very similar to the first, but instead of creating the HTML on the fly, theTPageProducer uses an existing HTM file to establish the basis for the response. TheTPageProducer.HTMLFile property is set to the specified file, and then the OnHTMLTag event occurs to replace a user-defined tag with the full path of the module name of the application.
In order to assure that the file can be found on any system that might run the app, a call is made to the Windows API function GetModuleFileName, which fills the specified buffer with the path to the calling module. This call is made within the little known SetString procedure which makes a string out of a PChar variable. The result is used to set theTPageProducer.HTMLFile property:
procedure TWebModule1.WebModule1Create(Sender: TObject);
var
  Path: array[0..MAX_PATH - 1] of Char;
  PathStr: string;
begin
  SetString(PathStr, Path, GetModuleFileName(HInstance, Path,        
       SizeOf(Path)));
  PageProducer1.HTMLFile := ExtractFilePath(PathStr) + 'appname.htm';
end;
Once the HTMLFile property has been set, the code is almost identical to the previous example:
procedure TWebModule1.WebModule1Actions0Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled:
Boolean);
begin
     {HTMLFile property was set in OnCreate of the datamodule}
     Response.Content := PageProducer1.Content;
     Handled := True;
end;


procedure TWebModule1.PageProducer1HTMLTag(Sender: TObject; Tag:
TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText:
String);
var
  Path: array[0..MAX_PATH - 1] of Char;
  PathStr: string;
begin
     case Tag of
       tgCustom:
         begin
           if CompareStr(TagString, 'AppName') = 0 then
           begin
                SetString(PathStr, Path, GetModuleFileName(HInstance,
                                Path, SizeOf(Path)));
                ReplaceText := PathStr;
           end;
         end;
     end;
end;
 

 however there are some problems with it- mainly that Delphi doesnt seem to know what the MAX_PATH var isnt recognised , and neither is the GetModuleFileName !!!! what am i missing??? do i need to use a special unit?

David
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10807065
ok ive fixed the above

I’m not trying to access anything outside of the CGI bin, however I just didn’t know how to access the stuff in the CGI bin - now I do :)

However I am still trying to figure out how I could cope with multiple simultaneous requests for the same file.... any ideas?

Thanks

David
0
 
LVL 1

Accepted Solution

by:
tanghz earned 500 total points
ID: 10807534
Hi,
Normally just use one CriticalSection var since you just have one block of code need independently processed.
unless you want another job to do in this way then you may need a different CS.

Just have a try, you will see it.


Good luck
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10807563
ok i see what u mean , like if i was using 2 different text files then i could use 2 different CriticalSection's  - 1 4 each :)

thannks :)

DAvid
0
 
LVL 1

Expert Comment

by:tanghz
ID: 10807579
Yeah, that's it.

Thanks for your points,
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question