473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Q: file exists?

Hello,
I am using this to open an excel file:
Response.Redirect(http://myServer/Files/myFile.xls)
How should I check if the file available first to get rid of error page.
Thanks,
Jim.

Nov 19 '05 #1
11 1550
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,
I am using this to open an excel file:
Response.Redirect(http://myServer/Files/myFile.xls)
How should I check if the file available first to get rid of error page.
Thanks,
Jim.

Nov 19 '05 #2
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in the
address bare. so if user is clever enough they will type and check other file
names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,
I am using this to open an excel file:
Response.Redirect(http://myServer/Files/myFile.xls)
How should I check if the file available first to get rid of error page.
Thanks,
Jim.


Nov 19 '05 #3
I think you can configure IIS to not serve up certain file types.
Another solution is to move the files outside the virtual directory.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in the address bare. so if user is clever enough they will type and check other file names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,
I am using this to open an excel file:
Response.Redirect(http://myServer/Files/myFile.xls)
How should I check if the file available first to get rid of error page. Thanks,
Jim.


Nov 19 '05 #4
Store the files outside the webdirectory and use an aspx page and
Response.OutputStream WriteFile to stream the file to the user

there are probably far better guides, but:
http://support.microsoft.com/kb/306654/EN-US/

for some ideas.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in the address bare. so if user is clever enough they will type and check other file names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,
I am using this to open an excel file:
Response.Redirect(http://myServer/Files/myFile.xls)
How should I check if the file available first to get rid of error page. Thanks,
Jim.


Nov 19 '05 #5
You need to combine one of those solutions with changing to a
Response.WriteFile approach...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Marina" <so*****@nospam.com> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
I think you can configure IIS to not serve up certain file types.
Another solution is to move the files outside the virtual directory.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in

the
address bare. so if user is clever enough they will type and check other

file
names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Hello,
> I am using this to open an excel file:
> Response.Redirect(http://myServer/Files/myFile.xls)
> How should I check if the file available first to get rid of error page. > Thanks,
> Jim.
>


Nov 19 '05 #6
If you want to prevent users from seeing other
file names in the Files directory, just open the
IIS Manager, select the directory, and make sure
the "Directory Browsing" property is unchecked.

After you do that, anybody who browses the
/files directory without a filename will get a
"You're not authorized" page.

Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in
the
address bare. so if user is clever enough they will type and check other
file
names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Hello,
> I am using this to open an excel file:
> Response.Redirect(http://myServer/Files/myFile.xls)
> How should I check if the file available first to get rid of error
> page.
> Thanks,
> Jim.
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.794 / Virus Database: 538 - Release Date: 11/10/2004
Nov 19 '05 #7
Ok. I put my files in a different drive. And changed
Response.Redirect("/Files/myFile.xls") to
Response.WriteFile(“D:\ Files\myFile.xls”)
But I could not see excel file in the browser anymore, lost of garbage? What
is problem?
"Marina" wrote:
I think you can configure IIS to not serve up certain file types.
Another solution is to move the files outside the virtual directory.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name in

the
address bare. so if user is clever enough they will type and check other

file
names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:
How about:
if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
Response.Redirect("/Files/myFile.xls");
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Hello,
> I am using this to open an excel file:
> Response.Redirect(http://myServer/Files/myFile.xls)
> How should I check if the file available first to get rid of error page. > Thanks,
> Jim.
>


Nov 19 '05 #8
If you look at the example on the microsoft site I provided, or do a little
reasearch, you'll see that the content-type must be set, that the buffer
most likely needs to be cleared and that the response must be ended right
after...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Ok. I put my files in a different drive. And changed
Response.Redirect("/Files/myFile.xls") to
Response.WriteFile("D:\ Files\myFile.xls")
But I could not see excel file in the browser anymore, lost of garbage? What is problem?
"Marina" wrote:
I think you can configure IIS to not serve up certain file types.
Another solution is to move the files outside the virtual directory.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Perfect. I have one more problem.
Response.Redirect("/Files/myFile.xls") open files and I see file name
in the
address bare. so if user is clever enough they will type and check
other file
names. What should I do? (I am using visual basic by the way. not C#.)
"Karl Seguin" wrote:

> How about:
> if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
> Response.Redirect("/Files/myFile.xls");
> }
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> news:8A**********************************@microsof t.com...
> > Hello,
> > I am using this to open an excel file:
> > Response.Redirect(http://myServer/Files/myFile.xls)
> > How should I check if the file available first to get rid of error

page.
> > Thanks,
> > Jim.
> >
>
>
>


Nov 19 '05 #9
I was trying to find a way to solve the problem without creating a new page.
Here is my new web form and page_load code.

BinaryData.aspx.vb:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim FilePath As String
'Set the appropriate ContentType.
Response.ContentType = "Application/x-msexcel"
'Get the physical path to the file.
FilePath = MapPath("D:\Files\myFile.xls")
'Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath)
Response.End()

End Sub

When I debug it I get this message.
Invalid path for MapPath 'D:\Files\myFile.xls'. A virtual path is expected.
Any idea?
"Karl Seguin" wrote:
If you look at the example on the microsoft site I provided, or do a little
reasearch, you'll see that the content-type must be set, that the buffer
most likely needs to be cleared and that the response must be ended right
after...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Ok. I put my files in a different drive. And changed
Response.Redirect("/Files/myFile.xls") to
Response.WriteFile("D:\ Files\myFile.xls")
But I could not see excel file in the browser anymore, lost of garbage?

What
is problem?
"Marina" wrote:
I think you can configure IIS to not serve up certain file types.
Another solution is to move the files outside the virtual directory.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
> Perfect. I have one more problem.
> Response.Redirect("/Files/myFile.xls") open files and I see file name in the
> address bare. so if user is clever enough they will type and check other file
> names. What should I do? (I am using visual basic by the way. not C#.)
>
>
> "Karl Seguin" wrote:
>
> > How about:
> > if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
> > Response.Redirect("/Files/myFile.xls");
> > }
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> > news:8A**********************************@microsof t.com...
> > > Hello,
> > > I am using this to open an excel file:
> > > Response.Redirect(http://myServer/Files/myFile.xls)
> > > How should I check if the file available first to get rid of error
page.
> > > Thanks,
> > > Jim.
> > >
> >
> >
> >


Nov 19 '05 #10
You don't need to MapPath if you are going to put the full physical path.

FilePath = "d:\Files\myFile.xls"

I originally had the mapPath in there because you were using a virtual
path...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I was trying to find a way to solve the problem without creating a new page. Here is my new web form and page_load code.

BinaryData.aspx.vb:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim FilePath As String
'Set the appropriate ContentType.
Response.ContentType = "Application/x-msexcel"
'Get the physical path to the file.
FilePath = MapPath("D:\Files\myFile.xls")
'Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath)
Response.End()

End Sub

When I debug it I get this message.
Invalid path for MapPath 'D:\Files\myFile.xls'. A virtual path is expected. Any idea?
"Karl Seguin" wrote:
If you look at the example on the microsoft site I provided, or do a little reasearch, you'll see that the content-type must be set, that the buffer
most likely needs to be cleared and that the response must be ended right after...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Ok. I put my files in a different drive. And changed
Response.Redirect("/Files/myFile.xls") to
Response.WriteFile("D:\ Files\myFile.xls")
But I could not see excel file in the browser anymore, lost of garbage?
What
is problem?
"Marina" wrote:

> I think you can configure IIS to not serve up certain file types.
> Another solution is to move the files outside the virtual directory.
>
> "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> news:94**********************************@microsof t.com...
> > Perfect. I have one more problem.
> > Response.Redirect("/Files/myFile.xls") open files and I see file
name in
> the
> > address bare. so if user is clever enough they will type and check

other
> file
> > names. What should I do? (I am using visual basic by the way. not

C#.) > >
> >
> > "Karl Seguin" wrote:
> >
> > > How about:
> > > if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) { > > > Response.Redirect("/Files/myFile.xls");
> > > }
> > >
> > > Karl
> > >
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> > > news:8A**********************************@microsof t.com...
> > > > Hello,
> > > > I am using this to open an excel file:
> > > > Response.Redirect(http://myServer/Files/myFile.xls)
> > > > How should I check if the file available first to get rid of error > page.
> > > > Thanks,
> > > > Jim.
> > > >
> > >
> > >
> > >
>
>
>


Nov 19 '05 #11
mmmm. it seems it requires me to add excel file to my project, I have many
files and folders, I can not do that, if that is the requirement, is there
any other way not to show address bar on the screen?

"JIM.H." wrote:
I was trying to find a way to solve the problem without creating a new page.
Here is my new web form and page_load code.

BinaryData.aspx.vb:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim FilePath As String
'Set the appropriate ContentType.
Response.ContentType = "Application/x-msexcel"
'Get the physical path to the file.
FilePath = MapPath("D:\Files\myFile.xls")
'Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath)
Response.End()

End Sub

When I debug it I get this message.
Invalid path for MapPath 'D:\Files\myFile.xls'. A virtual path is expected.
Any idea?
"Karl Seguin" wrote:
If you look at the example on the microsoft site I provided, or do a little
reasearch, you'll see that the content-type must be set, that the buffer
most likely needs to be cleared and that the response must be ended right
after...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Ok. I put my files in a different drive. And changed
Response.Redirect("/Files/myFile.xls") to
Response.WriteFile("D:\ Files\myFile.xls")
But I could not see excel file in the browser anymore, lost of garbage?

What
is problem?
"Marina" wrote:

> I think you can configure IIS to not serve up certain file types.
> Another solution is to move the files outside the virtual directory.
>
> "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> news:94**********************************@microsof t.com...
> > Perfect. I have one more problem.
> > Response.Redirect("/Files/myFile.xls") open files and I see file name

in
> the
> > address bare. so if user is clever enough they will type and check

other
> file
> > names. What should I do? (I am using visual basic by the way. not C#.)
> >
> >
> > "Karl Seguin" wrote:
> >
> > > How about:
> > > if (System.IO.File.Exists(Server.MapPath("/Files/myFile.xls"))) {
> > > Response.Redirect("/Files/myFile.xls");
> > > }
> > >
> > > Karl
> > >
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> > > news:8A**********************************@microsof t.com...
> > > > Hello,
> > > > I am using this to open an excel file:
> > > > Response.Redirect(http://myServer/Files/myFile.xls)
> > > > How should I check if the file available first to get rid of error
> page.
> > > > Thanks,
> > > > Jim.
> > > >
> > >
> > >
> > >
>
>
>


Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
18
by: Dan | last post by:
I have code like the following to test for existence of a file. I know the file is there, but File.Exists returns FALSE. The problem appears to be that the file is in a directory beneath "My...
6
by: Alex Chan | last post by:
Hi Group, I encountered something strange with File.Exists(string path). This function is simply to check whether a file exists in certain path. However, if the path starts with "file:\" in the...
2
by: Zeno Lee | last post by:
I'm using File.Exists to test a file on my C: drive. My program was strongly named and had caspol -af run on it to allow it to run from the network. There are 3 ways I am doing this: 1) Run...
2
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation...
4
by: DEWright_CA | last post by:
I am trying to see if a file exists in a virtual directory, and if so run a method. I try doing File.Exists and the method runs but the file isn't there. Is there a web version of File.Exists or...
3
by: Lou | last post by:
Question: I can't seem to get file.exists(filename) to return true when I search using wildcards, and I know there's a file in that dir with that extension. here's the path dim yesno as...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
8
by: Sweetiecakes | last post by:
In our series of "probably something simple"... I am doing a File.Exists operation to check if a file exists. Let's assume that this file is C:/test.txt. Now, if I do...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.