?
Solved

Severside text file access

Posted on 2004-04-07
10
Medium Priority
?
225 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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